[vlc-devel] [PATCH] variables: fix leak on non existent variable

Francois Cartegnie fcvlcdev at free.fr
Tue Feb 12 23:26:35 CET 2019


---
 src/misc/variables.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/misc/variables.c b/src/misc/variables.c
index a07684c58a..5d28c3343b 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -760,9 +760,9 @@ typedef enum
     vlc_list_callback
 } vlc_callback_type_t;
 
-static void AddCallback( vlc_object_t *p_this, const char *psz_name,
-                         callback_entry_t *restrict entry,
-                         vlc_callback_type_t i_type )
+static int AddCallback( vlc_object_t *p_this, const char *psz_name,
+                        callback_entry_t *restrict entry,
+                        vlc_callback_type_t i_type )
 {
     variable_t *p_var;
 
@@ -776,7 +776,7 @@ static void AddCallback( vlc_object_t *p_this, const char *psz_name,
         vlc_mutex_unlock( &p_priv->var_lock );
         msg_Err( p_this, "cannot add callback %p to nonexistent variable '%s'",
                  entry->p_callback, psz_name );
-        return;
+        return VLC_EGENERIC;
     }
 
     WaitUnused( p_this, p_var );
@@ -792,6 +792,7 @@ static void AddCallback( vlc_object_t *p_this, const char *psz_name,
     *pp = entry;
 
     vlc_mutex_unlock( &p_priv->var_lock );
+    return VLC_SUCCESS;
 }
 
 void (var_AddCallback)(vlc_object_t *p_this, const char *psz_name,
@@ -801,7 +802,8 @@ void (var_AddCallback)(vlc_object_t *p_this, const char *psz_name,
 
     entry->pf_value_callback = pf_callback;
     entry->p_data = p_data;
-    AddCallback(p_this, psz_name, entry, vlc_value_callback);
+    if( AddCallback(p_this, psz_name, entry, vlc_value_callback) )
+        free( entry );
 }
 
 static void DelCallback( vlc_object_t *p_this, const char *psz_name,
@@ -879,7 +881,8 @@ void (var_AddListCallback)(vlc_object_t *p_this, const char *psz_name,
 
     entry->pf_list_callback = pf_callback;
     entry->p_data = p_data;
-    AddCallback(p_this, psz_name, entry, vlc_list_callback);
+    if( AddCallback(p_this, psz_name, entry, vlc_list_callback) )
+        free( entry );
 }
 
 void (var_DelListCallback)(vlc_object_t *p_this, const char *psz_name,
-- 
2.20.1



More information about the vlc-devel mailing list