libFLAC: Fix memory leak
authorErik de Castro Lopo <erikd@mega-nerd.com>
Sat, 22 Aug 2015 10:28:44 +0000 (20:28 +1000)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Sat, 22 Aug 2015 10:28:47 +0000 (20:28 +1000)
Leak introduced in commit d9ae5e9128. Thanks to lvqcl <lvqcl.mail@gmail.com>
for pointing it out.

src/libFLAC/metadata_object.c

index ebe9801..05ca6b3 100644 (file)
@@ -1200,9 +1200,13 @@ FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__St
                        free(object->data.vorbis_comment.comments);
                        object->data.vorbis_comment.comments = 0;
                }
-               else if(0 == (object->data.vorbis_comment.comments = safe_realloc_(object->data.vorbis_comment.comments, new_size))) {
-                       object->data.vorbis_comment.num_comments = 0;
-                       return false;
+               else {
+                       FLAC__StreamMetadata_VorbisComment_Entry *oldptr = object->data.vorbis_comment.comments;
+                       if(0 == (object->data.vorbis_comment.comments = realloc(object->data.vorbis_comment.comments, new_size))) {
+                               vorbiscomment_entry_array_delete_(oldptr, object->data.vorbis_comment.num_comments);
+                               object->data.vorbis_comment.num_comments = 0;
+                               return false;
+                       }
                }
 
                /* if growing, zero all the length/pointers of new elements */