]> git.sesse.net Git - vlc/blobdiff - src/misc/variables.c
variables: fix a potential crash/double free.
[vlc] / src / misc / variables.c
index dc0e8e6fefaaa91e0c36b5359995e30b2fa39e11..f8bf3d8e951760f77f82c2bac06fa683677cc079 100644 (file)
@@ -68,7 +68,10 @@ static int CmpAddress( vlc_value_t v, vlc_value_t w ) { return v.p_address == w.
  * Local duplication functions, and local deallocation functions
  *****************************************************************************/
 static void DupDummy( vlc_value_t *p_val ) { (void)p_val; /* unused */ }
-static void DupString( vlc_value_t *p_val ) { if( p_val->psz_string ) p_val->psz_string = strdup( p_val->psz_string ); }
+static void DupString( vlc_value_t *p_val )
+{
+    p_val->psz_string = strdup( p_val->psz_string ? p_val->psz_string :  "" );
+}
 
 static void DupList( vlc_value_t *p_val )
 {
@@ -620,6 +623,8 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name,
             free( p_var->psz_text );
             if( p_val && p_val->psz_string )
                 p_var->psz_text = strdup( p_val->psz_string );
+            else
+                p_val->psz_text = NULL;
             break;
         case VLC_VAR_GETTEXT:
             p_val->psz_string = NULL;
@@ -1384,7 +1389,7 @@ static int InheritValue( vlc_object_t *p_this, const char *psz_name,
     int i_var;
     variable_t *p_var;
 
-    if( p_this->p_parent || ( p_this->p_libvlc && p_this != p_this->p_libvlc ) )
+    if( p_this->p_parent || ( p_this->p_libvlc && p_this != (vlc_object_t*) p_this->p_libvlc ) )
     {
         vlc_object_internals_t *p_priv;
 
@@ -1406,6 +1411,10 @@ static int InheritValue( vlc_object_t *p_this, const char *psz_name,
             /* Duplicate value if needed */
             p_var->ops->pf_dup( p_val );
 
+            /*msg_Dbg( p_this, "Inherited value for var %s from object %s",
+                     psz_name ? psz_name : "(null)",
+                     p_this->psz_object_name
+                         ? p_this->psz_object_name : "(Unknown)" );*/
             return VLC_SUCCESS;
         }
         else if ( p_this->p_parent ) /* We are still not there */
@@ -1460,9 +1469,12 @@ static int InheritValue( vlc_object_t *p_this, const char *psz_name,
             break;
         }
         default:
+            msg_Warn( p_this, "Could not inherit value for var %s "
+                              "from config. Invalid Type", psz_name );
             return VLC_ENOOBJ;
             break;
     }
+    /*msg_Dbg( p_this, "Inherited value for var %s from config", psz_name );*/
     return VLC_SUCCESS;
 }