[vlc-devel] commit: var_AcquireMutex: enforce constant mutex name ( Rémi Denis-Courmont )

git version control git at videolan.org
Sun Sep 7 11:19:17 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Sun Sep  7 12:17:49 2008 +0300| [03b701d58f53b02d8e735d8bfcd2047ed7fc6e3c] | committer: Rémi Denis-Courmont 

var_AcquireMutex: enforce constant mutex name

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

 include/vlc_variables.h |   17 +++++++++++++++++
 src/misc/variables.c    |    1 +
 2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/include/vlc_variables.h b/include/vlc_variables.h
index aa1c6b4..432691d 100644
--- a/include/vlc_variables.h
+++ b/include/vlc_variables.h
@@ -131,6 +131,23 @@ VLC_EXPORT( int, __var_Get, ( vlc_object_t *, const char *, vlc_value_t * ) );
 VLC_EXPORT( int, __var_Command, ( vlc_object_t *, const char *, const char *, const char *, char ** ) );
 
 VLC_EXPORT( vlc_mutex_t *, var_AcquireMutex, ( const char * ) );
+#ifdef __GNUC__
+static
+__attribute__((unused))
+__attribute__((noinline))
+__attribute__((error("variable mutex name leaks memory at run-time")))
+const char *nonconst_mutex_name( const char *str )
+{
+    return str;
+}
+
+# define check_named_mutex( m ) \
+    (__builtin_constant_p(m) ? m : nonconst_mutex_name(m))
+#else
+# define check_named_mutex( m ) (m)
+#endif
+
+#define var_AcquireMutex( n ) var_AcquireMutex(check_named_mutex(n))
 
 /**
  * __var_Create() with automatic casting.
diff --git a/src/misc/variables.c b/src/misc/variables.c
index 89faf07..315d6f1 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -848,6 +848,7 @@ int __var_Get( vlc_object_t *p_this, const char *psz_name, vlc_value_t *p_val )
 }
 
 
+#undef var_AcquireMutex
 /**
  * Finds a process-wide mutex, creates it if needed, and locks it.
  * Unlock with vlc_mutex_unlock().




More information about the vlc-devel mailing list