From 53fa75fdba19fab03adae053da31963dbd757eae Mon Sep 17 00:00:00 2001 From: moritz Date: Sat, 4 Aug 2007 16:39:09 +0000 Subject: [PATCH] Now that xalloc is pretty much an external entity, explicitly set freed pointers to NULL if we lateron expect them to be NULL (no longer rely on xalloc to do this for us.) git-svn-id: https://svn.xiph.org/trunk/ezstream@13436 0101bb08-14d6-0310-b084-bc0e0c8e3800 --- src/ezstream.c | 1 + src/metadata.c | 47 +++++++++++++++++++++++++++++++---------------- src/playlist.c | 15 ++++++++++----- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/ezstream.c b/src/ezstream.c index 494cfe8..9d07427 100644 --- a/src/ezstream.c +++ b/src/ezstream.c @@ -839,6 +839,7 @@ streamFile(shout_t *shout, const char *fileName) else printf("\n"); xfree(metaData); + metaData = NULL; } #ifdef HAVE_GETTIMEOFDAY diff --git a/src/metadata.c b/src/metadata.c index 86a213e..5ce75ab 100644 --- a/src/metadata.c +++ b/src/metadata.c @@ -109,8 +109,10 @@ metadata_use_taglib(metadata_t *md, FILE **filep) taglib_set_string_management_enabled(0); taglib_set_strings_unicode(0); - if (md->string != NULL) + if (md->string != NULL) { xfree(md->string); + md->string = NULL; + } if ((tf = taglib_file_new(md->filename)) == NULL) { md->string = metadata_get_name(md->filename); @@ -248,12 +250,18 @@ metadata_clean_md(metadata_t *md) abort(); } - if (md->string != NULL) + if (md->string != NULL) { xfree(md->string); - if (md->artist != NULL) + md->string = NULL; + } + if (md->artist != NULL) { xfree(md->artist); - if (md->title != NULL) + md->artist = NULL; + } + if (md->title != NULL) { xfree(md->title); + md->title = NULL; + } } void @@ -388,19 +396,20 @@ metadata_program(const char *program) } void -metadata_free(metadata_t **md) +metadata_free(metadata_t **md_p) { - metadata_t *tmp; + metadata_t *md; - if (md == NULL || *md == NULL) + if (md_p == NULL || (md = *md_p) == NULL) return; - tmp = *md; - - if (tmp->filename != NULL) - xfree(tmp->filename); - metadata_clean_md(tmp); - xfree(*md); + if (md->filename != NULL) { + xfree(md->filename); + md->filename = NULL; + } + metadata_clean_md(md); + xfree(*md_p); + *md_p = NULL; } @@ -467,18 +476,24 @@ metadata_program_update(metadata_t *md, enum metadata_request md_req) return (1); case METADATA_STRING: strlcpy(command, md->filename, sizeof(command)); - if (md->string != NULL) + if (md->string != NULL) { xfree(md->string); + md->string = NULL; + } break; case METADATA_ARTIST: snprintf(command, sizeof(command), "%s artist", md->filename); - if (md->artist != NULL) + if (md->artist != NULL) { xfree(md->artist); + md->artist = NULL; + } break; case METADATA_TITLE: snprintf(command, sizeof(command), "%s title", md->filename); - if (md->title != NULL) + if (md->title != NULL) { xfree(md->title); + md->title = NULL; + } break; default: printf("%s: metadata_program_update(): Internal error: Unknown md_req\n", diff --git a/src/playlist.c b/src/playlist.c index 0dfc8be..c69f128 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -244,7 +244,7 @@ playlist_program(const char *filename) void playlist_free(playlist_t **pl) { - size_t i; + size_t i; playlist_t *tmp; if (pl == NULL || *pl == NULL) @@ -252,15 +252,18 @@ playlist_free(playlist_t **pl) tmp = *pl; - if (tmp->filename != NULL) + if (tmp->filename != NULL) { xfree(tmp->filename); + tmp->filename = NULL; + } if (tmp->list != NULL) { if (tmp->size > 0) { for (i = 0; i < tmp->size / sizeof(char *); i++) { - if (tmp->list[i] != NULL) + if (tmp->list[i] != NULL) { xfree(tmp->list[i]); - else + tmp->list[i] = NULL; + } else break; } } @@ -268,8 +271,10 @@ playlist_free(playlist_t **pl) xfree(tmp->list); } - if (tmp->prog_track != NULL) + if (tmp->prog_track != NULL) { xfree(tmp->prog_track); + tmp->prog_track = NULL; + } xfree(*pl); }