]> git.sesse.net Git - vlc/blobdiff - modules/notify/growl.m
Fix potential double free (cid #1047496 and #1047497)
[vlc] / modules / notify / growl.m
index 028d9ed7121841ce2454fda51b0bc88537c00566..d9dae02e2a4e3a1c50f092b835741271fea3d5ba 100644 (file)
@@ -125,7 +125,7 @@ static int Open( vlc_object_t *p_this )
 
     p_playlist = pl_Get( p_intf );
     var_AddCallback( p_playlist, "item-change", ItemChange, p_intf );
-    var_AddCallback( p_playlist, "item-current", ItemChange, p_intf );
+    var_AddCallback( p_playlist, "activity", ItemChange, p_intf );
 
     [p_sys->o_growl_delegate registerToGrowl];
     return VLC_SUCCESS;
@@ -141,7 +141,7 @@ static void Close( vlc_object_t *p_this )
     intf_sys_t *p_sys = p_intf->p_sys;
 
     var_DelCallback( p_playlist, "item-change", ItemChange, p_intf );
-    var_DelCallback( p_playlist, "item-current", ItemChange, p_intf );
+    var_DelCallback( p_playlist, "activity", ItemChange, p_intf );
 
     [p_sys->o_growl_delegate release];
     free( p_sys );
@@ -162,24 +162,34 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
     char *psz_album         = NULL;
     input_item_t *p_item = newval.p_address;
 
-    bool b_is_item_current = !strcmp( "item-current", psz_var );
+    bool b_is_item_current = !strcmp( "activity", psz_var );
 
     /* Don't update each time an item has been preparsed */
     if( b_is_item_current )
     { /* stores the current input item id */
-        p_intf->p_sys->i_id = p_item->i_id;
-        p_intf->p_sys->i_item_changes = 0;
+        input_thread_t *p_input = playlist_CurrentInput( (playlist_t*)p_this );
+        if( !p_input )
+            return VLC_SUCCESS;
+
+        p_item = input_GetItem( p_input );
+        if( p_intf->p_sys->i_id != p_item->i_id )
+        {
+            p_intf->p_sys->i_id = p_item->i_id;
+            p_intf->p_sys->i_item_changes = 0;
+        }
+
+        vlc_object_release( p_input );
         return VLC_SUCCESS;
     }
     /* ignore items which weren't pre-parsed yet */
     else if( !input_item_IsPreparsed(p_item) )
         return VLC_SUCCESS;
     else
-    {
-        if( p_item->i_id != p_intf->p_sys->i_id ) { /* "item-change" */
-            p_intf->p_sys->i_item_changes = 0;
+    {   /* "item-change" */
+        
+        if( p_item->i_id != p_intf->p_sys->i_id )
             return VLC_SUCCESS;
-        }
+
         /* Some variable bitrate inputs call "item-change" callbacks each time
          * their length is updated, that is several times per second.
          * We'll limit the number of changes to 1 per input. */
@@ -189,18 +199,6 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
         p_intf->p_sys->i_item_changes++;
     }
 
-
-    input_thread_t *p_input = playlist_CurrentInput( (playlist_t*)p_this );
-
-    if( !p_input ) return VLC_SUCCESS;
-
-    if( p_input->b_dead || !input_GetItem(p_input)->psz_name )
-    {
-        /* Not playing anything ... */
-        vlc_object_release( p_input );
-        return VLC_SUCCESS;
-    }
-
     /* Playing something ... */
     if( input_item_GetNowPlaying( p_item ) )
         psz_title = input_item_GetNowPlaying( p_item );
@@ -209,7 +207,6 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
     if( EMPTY_STR( psz_title ) )
     {
         free( psz_title );
-        vlc_object_release( p_input );
         return VLC_SUCCESS;
     }
 
@@ -232,7 +229,6 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
         free( psz_title );
         free( psz_artist );
         free( psz_album );
-        vlc_object_release( p_input );
         return VLC_ENOMEM;
     }
 
@@ -252,7 +248,6 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
     free( psz_arturl );
     free( psz_tmp );
 
-    vlc_object_release( p_input );
     return VLC_SUCCESS;
 }