[vlc-commits] Warn about dangling variable callbacks

Rémi Denis-Courmont git at videolan.org
Mon Aug 8 22:51:38 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Aug  8 23:50:53 2011 +0300| [c2b1d5b2e9ae8df2173b57272873ec8db31f4bb4] | committer: Rémi Denis-Courmont

Warn about dangling variable callbacks

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c2b1d5b2e9ae8df2173b57272873ec8db31f4bb4
---

 src/misc/variables.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/src/misc/variables.c b/src/misc/variables.c
index 4e7fe09..fc789ae 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -42,6 +42,9 @@
 #include <assert.h>
 #include <math.h>
 #include <limits.h>
+#ifdef __GLIBC__
+# include <dlfcn.h>
+#endif
 
 /*****************************************************************************
  * Private types
@@ -167,6 +170,25 @@ static void Destroy( variable_t *p_var )
         free( p_var->choices.p_values );
         free( p_var->choices_text.p_values );
     }
+#ifndef NDEBUG
+    for (int i = 0; i < p_var->i_entries; i++)
+    {
+        const char *file = "?", *symbol = "?";
+        const void *addr = p_var->p_entries[i].pf_callback;
+# ifdef __GLIBC__
+        Dl_info info;
+
+        if (dladdr (addr, &info))
+        {
+            if (info.dli_fname) file = info.dli_fname;
+            if (info.dli_sname) symbol = info.dli_sname;
+        }
+# endif
+        fprintf (stderr, "Error: callback on \"%s\" dangling %s(%s)[%p]\n",
+                 p_var->psz_name, file, symbol, addr);
+    }
+#endif
+
     free( p_var->psz_name );
     free( p_var->psz_text );
     free( p_var->p_entries );



More information about the vlc-commits mailing list