]> git.tue.mpg.de Git - paraslash.git/commitdiff
mp4: free(NULL) is OK.
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 9 Aug 2021 17:59:41 +0000 (19:59 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 30 May 2022 19:37:35 +0000 (21:37 +0200)
Also remove a initialization to NULL after the free() because it is
immediately followed by an assignment to the same variable.

mp4.c

diff --git a/mp4.c b/mp4.c
index 576f15741e251b12f9858745ea2333443b31b825..9b09a8f407822f6baee40a0440b729fb7a35787d 100644 (file)
--- a/mp4.c
+++ b/mp4.c
@@ -644,8 +644,7 @@ static int32_t mp4ff_read_esds(mp4ff_t * f)
        f->track[f->total_tracks - 1]->decoderConfigLen =
                mp4ff_read_mp4_descr_length(f);
 
-       if (f->track[f->total_tracks - 1]->decoderConfig)
-               free(f->track[f->total_tracks - 1]->decoderConfig);
+       free(f->track[f->total_tracks - 1]->decoderConfig);
        f->track[f->total_tracks - 1]->decoderConfig =
                para_malloc(f->track[f->total_tracks - 1]->decoderConfigLen);
        if (f->track[f->total_tracks - 1]->decoderConfig) {
@@ -771,8 +770,7 @@ static int32_t mp4ff_tag_add_field(mp4ff_metadata_t * tags, const char *item,
        tags->tags = (mp4ff_tag_t *) realloc(tags->tags,
                (tags->count + 1) * sizeof (mp4ff_tag_t));
        if (!tags->tags) {
-               if (backup)
-                       free(backup);
+               free(backup);
                return 0;
        } else {
                tags->tags[tags->count].item = strdup(item);
@@ -786,10 +784,8 @@ static int32_t mp4ff_tag_add_field(mp4ff_metadata_t * tags, const char *item,
                }
 
                if (!tags->tags[tags->count].item || !tags->tags[tags->count].value) {
-                       if (!tags->tags[tags->count].item)
-                               free(tags->tags[tags->count].item);
-                       if (!tags->tags[tags->count].value)
-                               free(tags->tags[tags->count].value);
+                       free(tags->tags[tags->count].item);
+                       free(tags->tags[tags->count].value);
                        tags->tags[tags->count].item = NULL;
                        tags->tags[tags->count].value = NULL;
                        tags->tags[tags->count].len = 0;
@@ -1034,10 +1030,7 @@ static int32_t mp4ff_parse_tag(mp4ff_t * f, const uint8_t parent_atom_type,
                                        done = 1;
                                }
                        } else {
-                               if (data) {
-                                       free(data);
-                                       data = NULL;
-                               }
+                               free(data);
                                data = mp4ff_read_string(f, (uint32_t) (subsize - (header_size + 8)));
                                len = (uint32_t) (subsize - (header_size + 8));
                        }
@@ -1045,8 +1038,7 @@ static int32_t mp4ff_parse_tag(mp4ff_t * f, const uint8_t parent_atom_type,
                        if (!done) {
                                mp4ff_read_char(f);     /* version */
                                mp4ff_read_int24(f);    /* flags */
-                               if (name)
-                                       free(name);
+                               free(name);
                                name = mp4ff_read_string(f, (uint32_t) (subsize - (header_size + 4)));
                        }
                }
@@ -1064,10 +1056,10 @@ static int32_t mp4ff_parse_tag(mp4ff_t * f, const uint8_t parent_atom_type,
 
                free(data);
        }
-       if (name)
-               free(name);
+       free(name);
        return 1;
 }
+
 static int32_t mp4ff_read_mdhd(mp4ff_t * f)
 {
        uint32_t version;
@@ -1288,15 +1280,10 @@ static int32_t mp4ff_tag_delete(mp4ff_metadata_t * tags)
        uint32_t i;
 
        for (i = 0; i < tags->count; i++) {
-               if (tags->tags[i].item)
-                       free(tags->tags[i].item);
-               if (tags->tags[i].value)
-                       free(tags->tags[i].value);
+               free(tags->tags[i].item);
+               free(tags->tags[i].value);
        }
-
-       if (tags->tags)
-               free(tags->tags);
-
+       free(tags->tags);
        tags->tags = NULL;
        tags->count = 0;
 
@@ -1309,34 +1296,22 @@ void mp4ff_close(mp4ff_t * ff)
 
        for (i = 0; i < ff->total_tracks; i++) {
                if (ff->track[i]) {
-                       if (ff->track[i]->stsz_table)
-                               free(ff->track[i]->stsz_table);
-                       if (ff->track[i]->stts_sample_count)
-                               free(ff->track[i]->stts_sample_count);
-                       if (ff->track[i]->stts_sample_delta)
-                               free(ff->track[i]->stts_sample_delta);
-                       if (ff->track[i]->stsc_first_chunk)
-                               free(ff->track[i]->stsc_first_chunk);
-                       if (ff->track[i]->stsc_samples_per_chunk)
-                               free(ff->track[i]->stsc_samples_per_chunk);
-                       if (ff->track[i]->stsc_sample_desc_index)
-                               free(ff->track[i]->stsc_sample_desc_index);
-                       if (ff->track[i]->stco_chunk_offset)
-                               free(ff->track[i]->stco_chunk_offset);
-                       if (ff->track[i]->decoderConfig)
-                               free(ff->track[i]->decoderConfig);
-                       if (ff->track[i]->ctts_sample_count)
-                               free(ff->track[i]->ctts_sample_count);
-                       if (ff->track[i]->ctts_sample_offset)
-                               free(ff->track[i]->ctts_sample_offset);
+                       free(ff->track[i]->stsz_table);
+                       free(ff->track[i]->stts_sample_count);
+                       free(ff->track[i]->stts_sample_delta);
+                       free(ff->track[i]->stsc_first_chunk);
+                       free(ff->track[i]->stsc_samples_per_chunk);
+                       free(ff->track[i]->stsc_sample_desc_index);
+                       free(ff->track[i]->stco_chunk_offset);
+                       free(ff->track[i]->decoderConfig);
+                       free(ff->track[i]->ctts_sample_count);
+                       free(ff->track[i]->ctts_sample_offset);
                        free(ff->track[i]);
                }
        }
 
        mp4ff_tag_delete(&(ff->tags));
-
-       if (ff)
-               free(ff);
+       free(ff);
 }
 
 static int32_t mp4ff_chunk_of_sample(const mp4ff_t * f, const int32_t track,
@@ -1773,8 +1748,7 @@ static unsigned membuffer_error(const membuffer * buf)
 
 static void membuffer_free(membuffer * buf)
 {
-       if (buf->data)
-               free(buf->data);
+       free(buf->data);
        free(buf);
 }