[vlc-commits] libvlc: fix potentially leaked error message

Rémi Denis-Courmont git at videolan.org
Thu Feb 27 19:33:40 CET 2014


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Feb 27 20:33:31 2014 +0200| [6ae117da3f1dac3b8fcf950d07abe9c8d61bdcea] | committer: Rémi Denis-Courmont

libvlc: fix potentially leaked error message

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

 lib/error.c |   27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/lib/error.c b/lib/error.c
index 45397a6..a86c95b 100644
--- a/lib/error.c
+++ b/lib/error.c
@@ -30,8 +30,10 @@ static const char oom[] = "Out of memory";
 /* TODO: use only one thread-specific key for whole libvlc */
 static vlc_threadvar_t context;
 
-static vlc_mutex_t lock = VLC_STATIC_MUTEX;
-static uintptr_t refs = 0;
+static char *get_error (void)
+{
+    return vlc_threadvar_get (context);
+}
 
 static void free_msg (void *msg)
 {
@@ -39,6 +41,14 @@ static void free_msg (void *msg)
         free (msg);
 }
 
+static void free_error (void)
+{
+    free_msg (get_error ());
+}
+
+static vlc_mutex_t lock = VLC_STATIC_MUTEX;
+static uintptr_t refs = 0;
+
 void libvlc_threads_init (void)
 {
     vlc_mutex_lock (&lock);
@@ -52,20 +62,13 @@ void libvlc_threads_deinit (void)
     vlc_mutex_lock (&lock);
     assert (refs > 0);
     if (--refs == 0)
+    {
+        free_error ();
         vlc_threadvar_delete (&context);
+    }
     vlc_mutex_unlock (&lock);
 }
 
-static char *get_error (void)
-{
-    return vlc_threadvar_get (context);
-}
-
-static void free_error (void)
-{
-    free_msg (get_error ());
-}
-
 /**
  * Gets a human-readable error message for the last LibVLC error in the calling
  * thread. The resulting string is valid until another error occurs (at least



More information about the vlc-commits mailing list