libFLAC: Add function safe_realloc_()
[flac.git] / src / libFLAC / metadata_object.c
index 1bfa0b4..ebe9801 100644 (file)
@@ -954,13 +954,8 @@ FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMe
                        free(object->data.seek_table.points);
                        object->data.seek_table.points = 0;
                }
-               else {
-                       void *oldptr = object->data.seek_table.points;
-                       if(0 == (object->data.seek_table.points = realloc(object->data.seek_table.points, new_size))) {
-                               free(oldptr);
-                               return false;
-                       }
-               }
+               else if(0 == (object->data.seek_table.points = safe_realloc_(object->data.seek_table.points, new_size)))
+                       return false;
 
                /* if growing, set new elements to placeholders */
                if(new_size > old_size) {
@@ -1205,13 +1200,9 @@ 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 {
-                       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;
-                       }
+               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;
                }
 
                /* if growing, zero all the length/pointers of new elements */
@@ -1513,13 +1504,8 @@ FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__St
                        free(track->indices);
                        track->indices = 0;
                }
-               else {
-                       void *oldptr = track->indices;
-                       if(0 == (track->indices = realloc(track->indices, new_size))) {
-                               free(oldptr);
-                               return false;
-                       }
-               }
+               else if(0 == (track->indices = safe_realloc_(track->indices, new_size)))
+                       return false;
 
                /* if growing, zero all the lengths/pointers of new elements */
                if(new_size > old_size)
@@ -1613,13 +1599,8 @@ FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMet
                        free(object->data.cue_sheet.tracks);
                        object->data.cue_sheet.tracks = 0;
                }
-               else {
-                       void *oldptr = object->data.cue_sheet.tracks;
-                       if(0 == (object->data.cue_sheet.tracks = realloc(object->data.cue_sheet.tracks, new_size))) {
-                               free(oldptr);
-                               return false;
-                       }
-               }
+               else if(0 == (object->data.cue_sheet.tracks = safe_realloc_(object->data.cue_sheet.tracks, new_size)))
+                       return false;
 
                /* if growing, zero all the lengths/pointers of new elements */
                if(new_size > old_size)