]> git.sesse.net Git - vlc/commitdiff
core: correct memory leak
authorErwan Tulou <erwan10@videolan.org>
Sat, 2 Jan 2010 22:09:36 +0000 (23:09 +0100)
committerRémi Duraffort <ivoire@videolan.org>
Tue, 5 Jan 2010 17:19:16 +0000 (18:19 +0100)
var_Change with VLC_VAR_SETVALUE showed a memory leak when dealing with a STRING variable.
The pf_dup function must not be called directy with a parameter passed by the caller.
otherwise, a reference is lost (memory leak)

Signed-off-by: Rémi Duraffort <ivoire@videolan.org>
src/misc/variables.c

index d681162a4d25d3a0bcb5fcd3445a95b2bfa1802e..a6e61a95453dedd16be6d70b44637c9ff19f8da4 100644 (file)
@@ -407,6 +407,7 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name,
     int i_var, i;
     variable_t *p_var;
     vlc_value_t oldval;
+    vlc_value_t newval;
 
     assert( p_this );
 
@@ -562,13 +563,14 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name,
             break;
         case VLC_VAR_SETVALUE:
             /* Duplicate data if needed */
-            p_var->ops->pf_dup( p_val );
+            newval = *p_val;
+            p_var->ops->pf_dup( &newval );
             /* Backup needed stuff */
             oldval = p_var->val;
             /* Check boundaries and list */
-            CheckValue( p_var, p_val );
+            CheckValue( p_var, &newval );
             /* Set the variable */
-            p_var->val = *p_val;
+            p_var->val = newval;
             /* Free data if needed */
             p_var->ops->pf_free( &oldval );
             break;