From dc8116dcd760675f2cb19bd9ad846a25a16f465b Mon Sep 17 00:00:00 2001 From: Gildas Bazin Date: Fri, 23 Apr 2004 06:53:00 +0000 Subject: [PATCH] * src/playlist/item.c,item-ext.c: fixed memory leaks. --- src/playlist/item-ext.c | 68 +++++------------------------------------ src/playlist/item.c | 6 ++++ 2 files changed, 14 insertions(+), 60 deletions(-) diff --git a/src/playlist/item-ext.c b/src/playlist/item-ext.c index 8a829ef064..75c3dcdf40 100644 --- a/src/playlist/item-ext.c +++ b/src/playlist/item-ext.c @@ -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--; diff --git a/src/playlist/item.c b/src/playlist/item.c index f86290b924..2a0225d098 100644 --- a/src/playlist/item.c +++ b/src/playlist/item.c @@ -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 ); -- 2.39.5