]> git.sesse.net Git - vlc/commitdiff
* src/playlist/item.c,item-ext.c: fixed memory leaks.
authorGildas Bazin <gbazin@videolan.org>
Fri, 23 Apr 2004 06:53:00 +0000 (06:53 +0000)
committerGildas Bazin <gbazin@videolan.org>
Fri, 23 Apr 2004 06:53:00 +0000 (06:53 +0000)
src/playlist/item-ext.c
src/playlist/item.c

index 8a829ef0640cb15c4c6d440c7ed00fa3c71c7604..75c3dcdf40972a4f4cf2bd42ca1ba033b7cab3c4 100644 (file)
@@ -57,8 +57,6 @@ int playlist_AddExt( playlist_t *p_playlist, const char * psz_uri,
     playlist_item_t *p_item =
         playlist_ItemNew( p_playlist , psz_uri, psz_name );
 
-    int i;
-
     if( p_item == NULL )
     {
         msg_Err( p_playlist, "unable to add item to playlist" );
@@ -66,22 +64,20 @@ int playlist_AddExt( playlist_t *p_playlist, const char * psz_uri,
     }
 
     p_item->input.i_duration = i_duration;
-
     p_item->input.i_options = i_options;
     p_item->input.ppsz_options = NULL;
-    for( i = 0; i < i_options; i++ )
+
+    for( p_item->input.i_options = 0; p_item->input.i_options < i_options;
+         p_item->input.i_options++ )
     {
-        if( i == 0 )
+        if( !p_item->input.i_options )
         {
             p_item->input.ppsz_options = malloc( i_options * sizeof(char *) );
-            if( !p_item->input.ppsz_options )
-            {
-                p_item->input.i_options = 0;
-                break;
-            }
+            if( !p_item->input.ppsz_options ) break;
         }
 
-        p_item->input.ppsz_options[i] = strdup( ppsz_options[i] );
+        p_item->input.ppsz_options[p_item->input.i_options] =
+            strdup( ppsz_options[p_item->input.i_options] );
     }
 
     return playlist_AddItem( p_playlist, p_item, i_mode, i_pos );
@@ -374,57 +370,9 @@ int playlist_Delete( playlist_t * p_playlist, int i_pos )
 
         msg_Dbg( p_playlist, "deleting playlist item `%s'",
                  p_item->input.psz_name );
-#if 0
-        int i,j;
-
-        vlc_mutex_lock( &p_item->lock );
-
-        if( p_item->psz_name )
-        {
-            free( p_item->psz_name );
-        }
-        if( p_item->psz_uri )
-        {
-            free( p_item->psz_uri );
-        }
 
-        /* Free the info categories. Welcome to the segfault factory */
-        if( p_item->i_categories > 0 )
-        {
-            for( i = 0; i < p_item->i_categories; i++ )
-            {
-                for( j= 0 ; j < p_item->pp_categories[i]->i_infos; j++)
-                {
-                    if( p_item->pp_categories[i]->pp_infos[j]->psz_name)
-                    {
-                        free( p_item->pp_categories[i]->
-                                      pp_infos[j]->psz_name);
-                    }
-                    if( p_item->pp_categories[i]->pp_infos[j]->psz_value)
-                    {
-                        free( p_item->pp_categories[i]->
-                                      pp_infos[j]->psz_value);
-                    }
-                    free( p_item->pp_categories[i]->pp_infos[j] );
-                }
-                if( p_item->pp_categories[i]->i_infos )
-                    free( p_item->pp_categories[i]->pp_infos );
-
-                if( p_item->pp_categories[i]->psz_name)
-                {
-                    free( p_item->pp_categories[i]->psz_name );
-                }
-                free( p_item->pp_categories[i] );
-            }
-            free( p_item->pp_categories );
-        }
-
-        /* XXX: what if the item is still in use? */
-#endif
         playlist_ItemDelete( p_item );
-#if 0
-        free( p_item );
-#endif
+
         if( i_pos <= p_playlist->i_index )
         {
             p_playlist->i_index--;
index f86290b924fded5dcfc22bdf0f986adeb59d20dc..2a0225d098214371ce77e5c2a5007ac0f3be8283 100644 (file)
@@ -110,6 +110,12 @@ void playlist_ItemDelete( playlist_item_t *p_item )
         free( p_item->input.pp_categories );
     }
 
+    for( ; p_item->input.i_options > 0; p_item->input.i_options-- )
+    {
+        free( p_item->input.ppsz_options[p_item->input.i_options - 1] );
+        if( p_item->input.i_options == 1 ) free( p_item->input.ppsz_options );
+    }
+
     vlc_mutex_unlock( &p_item->input.lock );
     vlc_mutex_destroy( &p_item->input.lock );