From 82d5b54109a8409df48f0b9a02add1dcce01780b Mon Sep 17 00:00:00 2001 From: Petri Hintukainen Date: Thu, 24 Nov 2011 11:46:07 +0200 Subject: Fixed leaks in input plugins --HG-- branch : point-release --- src/input/input_cdda.c | 41 +++++++++++++++++++++++++++-------------- src/input/input_file.c | 11 ++++++++--- src/input/input_smb.c | 10 ++++++++-- 3 files changed, 43 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/input/input_cdda.c b/src/input/input_cdda.c index 22dfcac4c..4da456384 100644 --- a/src/input/input_cdda.c +++ b/src/input/input_cdda.c @@ -187,7 +187,7 @@ typedef struct { int mrls_allocated_entries; xine_mrl_t **mrls; - char *autoplaylist[MAX_TRACKS]; + char **autoplaylist; } cdda_input_class_t; @@ -2545,14 +2545,7 @@ static xine_mrl_t** cdda_class_get_dir(input_class_t *this_gen, } for (i = 0 ; i < num_tracks ; i++) { if (i < this->mrls_allocated_entries) { - if (this->mrls[i]->origin) - free(this->mrls[i]->origin); - if (this->mrls[i]->mrl) - free(this->mrls[i]->mrl); - if (this->mrls[i]->link) { - free(this->mrls[i]->link); - this->mrls[i]->link = NULL; - } + MRL_ZERO(this->mrls[i]); } else { this->mrls[i] = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t)); @@ -2578,6 +2571,21 @@ static xine_mrl_t** cdda_class_get_dir(input_class_t *this_gen, return this->mrls; } +static void free_autoplay_list(cdda_input_class_t *this) +{ + /* free old playlist */ + if (this->autoplaylist) { + unsigned int i; + for( i = 0; this->autoplaylist[i]; i++ ) { + free( this->autoplaylist[i] ); + this->autoplaylist[i] = NULL; + } + + free(this->autoplaylist); + this->autoplaylist = NULL; + } +} + static char ** cdda_class_get_autoplay_list (input_class_t *this_gen, int *num_files) { @@ -2589,11 +2597,7 @@ static char ** cdda_class_get_autoplay_list (input_class_t *this_gen, lprintf("cdda_class_get_autoplay_list for >%s<\n", this->cdda_device); - /* free old playlist */ - for( i = 0; this->autoplaylist[i]; i++ ) { - free( this->autoplaylist[i] ); - this->autoplaylist[i] = NULL; - } + free_autoplay_list(this); /* get the CD TOC */ toc = init_cdrom_toc(); @@ -2651,6 +2655,8 @@ static char ** cdda_class_get_autoplay_list (input_class_t *this_gen, num_tracks--; if (num_tracks >= MAX_TRACKS-1) num_tracks = MAX_TRACKS - 2; + + this->autoplaylist = calloc(num_tracks + 2, sizeof(char *)); for ( i = 0; i <= num_tracks; i++ ) this->autoplaylist[i] = _x_asprintf("cdda:/%d",i+toc->first_track); @@ -2779,7 +2785,14 @@ static void cdda_class_dispose (input_class_t *this_gen) { config->unregister_callback(config, "media.audio_cd.drive_slowdown"); #endif + free_autoplay_list(this); + + while (this->mrls_allocated_entries) { + MRL_ZERO(this->mrls[this->mrls_allocated_entries - 1]); + free(this->mrls[this->mrls_allocated_entries--]); + } free (this->mrls); + free (this); } diff --git a/src/input/input_file.c b/src/input/input_file.c index bb8afef92..2c56ae232 100644 --- a/src/input/input_file.c +++ b/src/input/input_file.c @@ -850,7 +850,7 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen, this->mrls[num_files] = calloc(1, sizeof(xine_mrl_t)); } else - memset(this->mrls[num_files], 0, sizeof(xine_mrl_t)); + MRL_ZERO(this->mrls[num_files]); MRL_DUPLICATE(&dir_files[i], this->mrls[num_files]); @@ -868,7 +868,7 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen, this->mrls[num_files] = calloc(1, sizeof(xine_mrl_t)); } else - memset(this->mrls[num_files], 0, sizeof(xine_mrl_t)); + MRL_ZERO(this->mrls[num_files]); MRL_DUPLICATE(&hide_files[i], this->mrls[num_files]); @@ -886,7 +886,7 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen, this->mrls[num_files] = calloc(1, sizeof(xine_mrl_t)); } else - memset(this->mrls[num_files], 0, sizeof(xine_mrl_t)); + MRL_ZERO(this->mrls[num_files]); MRL_DUPLICATE(&norm_files[i], this->mrls[num_files]); @@ -954,7 +954,12 @@ static void file_class_dispose (input_class_t *this_gen) { config->unregister_callback(config, "media.files.origin_path"); + while(this->mrls_allocated_entries) { + MRL_ZERO(this->mrls[this->mrls_allocated_entries - 1]); + free(this->mrls[this->mrls_allocated_entries--]); + } free (this->mrls); + free (this); } diff --git a/src/input/input_smb.c b/src/input/input_smb.c index d82ab0aa7..e3ad51eb1 100644 --- a/src/input/input_smb.c +++ b/src/input/input_smb.c @@ -356,7 +356,7 @@ static xine_mrl_t **smb_class_get_dir (input_class_t *this_gen, (this->mrls_allocated_entries+1) * sizeof(xine_mrl_t*)); this->mrls[num_files] = calloc(1, sizeof(xine_mrl_t)); }else - memset(this->mrls[num_files], 0, sizeof(xine_mrl_t)); + MRL_ZERO(this->mrls[num_files]); MRL_DUPLICATE(&dir_files[i], this->mrls[num_files]); @@ -373,7 +373,7 @@ static xine_mrl_t **smb_class_get_dir (input_class_t *this_gen, (this->mrls_allocated_entries+1) * sizeof(xine_mrl_t*)); this->mrls[num_files] = calloc(1, sizeof(xine_mrl_t)); }else - memset(this->mrls[num_files], 0, sizeof(xine_mrl_t)); + MRL_ZERO(this->mrls[num_files]); MRL_DUPLICATE(&norm_files[i], this->mrls[num_files]); @@ -456,6 +456,12 @@ smb_class_dispose (input_class_t *this_gen) { smb_input_class_t *this = (smb_input_class_t *) this_gen; + while(this->mrls_allocated_entries) { + MRL_ZERO(this->mrls[this->mrls_allocated_entries - 1]); + free(this->mrls[this->mrls_allocated_entries--]); + } + free(this->mrls); + free (this); } -- cgit v1.2.3