diff options
-rw-r--r-- | src/flac/main.c | 8 | ||||
-rw-r--r-- | src/libFLAC/metadata_object.c | 18 | ||||
-rw-r--r-- | src/libFLAC/stream_decoder.c | 6 | ||||
-rw-r--r-- | src/libFLAC/stream_encoder.c | 2 | ||||
-rw-r--r-- | src/metaflac/options.c | 7 | ||||
-rw-r--r-- | src/test_libFLAC/bitbuffer.c | 10 | ||||
-rw-r--r-- | src/test_libFLAC/metadata_manip.c | 2 |
7 files changed, 41 insertions, 12 deletions
diff --git a/src/flac/main.c b/src/flac/main.c index 3f9b5126..3106fd6e 100644 --- a/src/flac/main.c +++ b/src/flac/main.c @@ -980,8 +980,14 @@ int parse_option(int short_option, const char *long_option, const char *option_a void free_options() { - if(0 != option_values.filenames) + unsigned i; + if(0 != option_values.filenames) { + for(i = 0; i < option_values.num_files; i++) { + if(0 != option_values.filenames[i]) + free(option_values.filenames[i]); + } free(option_values.filenames); + } if(0 != option_values.vorbis_comment) FLAC__metadata_object_delete(option_values.vorbis_comment); } diff --git a/src/libFLAC/metadata_object.c b/src/libFLAC/metadata_object.c index 3e3d33ef..439902c3 100644 --- a/src/libFLAC/metadata_object.c +++ b/src/libFLAC/metadata_object.c @@ -392,8 +392,10 @@ FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMet } break; case FLAC__METADATA_TYPE_VORBIS_COMMENT: - if(0 != to->data.vorbis_comment.vendor_string.entry) + if(0 != to->data.vorbis_comment.vendor_string.entry) { free(to->data.vorbis_comment.vendor_string.entry); + to->data.vorbis_comment.vendor_string.entry = 0; + } if(!copy_vcentry_(&to->data.vorbis_comment.vendor_string, &object->data.vorbis_comment.vendor_string)) { FLAC__metadata_object_delete(to); return 0; @@ -446,16 +448,22 @@ void FLAC__metadata_object_delete_data(FLAC__StreamMetadata *object) case FLAC__METADATA_TYPE_PADDING: break; case FLAC__METADATA_TYPE_APPLICATION: - if(0 != object->data.application.data) + if(0 != object->data.application.data) { free(object->data.application.data); + object->data.application.data = 0; + } break; case FLAC__METADATA_TYPE_SEEKTABLE: - if(0 != object->data.seek_table.points) + if(0 != object->data.seek_table.points) { free(object->data.seek_table.points); + object->data.seek_table.points = 0; + } break; case FLAC__METADATA_TYPE_VORBIS_COMMENT: - if(0 != object->data.vorbis_comment.vendor_string.entry) + if(0 != object->data.vorbis_comment.vendor_string.entry) { free(object->data.vorbis_comment.vendor_string.entry); + object->data.vorbis_comment.vendor_string.entry = 0; + } if(0 != object->data.vorbis_comment.comments) { FLAC__ASSERT(object->data.vorbis_comment.num_comments > 0); vorbiscomment_entry_array_delete_(object->data.vorbis_comment.comments, object->data.vorbis_comment.num_comments); @@ -1144,7 +1152,7 @@ FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__Stre track = &object->data.cue_sheet.tracks[track_num]; /* move all indices > index_num backward one space */ - memmove(&track->indices[index_num], &track->indices[index_num+1], sizeof(FLAC__StreamMetadata_CueSheet_Track)*(track->num_indices-index_num-1)); + memmove(&track->indices[index_num], &track->indices[index_num+1], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(track->num_indices-index_num-1)); FLAC__metadata_object_cuesheet_track_resize_indices(object, track_num, track->num_indices-1); cuesheet_calculate_length_(object); diff --git a/src/libFLAC/stream_decoder.c b/src/libFLAC/stream_decoder.c index 0071eba7..aca94069 100644 --- a/src/libFLAC/stream_decoder.c +++ b/src/libFLAC/stream_decoder.c @@ -296,8 +296,7 @@ FLAC_API void FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder) FLAC__ASSERT(0 != decoder); if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED) return; - if(decoder->private_->has_seek_table) { - FLAC__ASSERT(0 != decoder->private_->seek_table.data.seek_table.points); + if(0 != decoder->private_->seek_table.data.seek_table.points) { free(decoder->private_->seek_table.data.seek_table.points); decoder->private_->seek_table.data.seek_table.points = 0; decoder->private_->has_seek_table = false; @@ -1030,7 +1029,8 @@ FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_ decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH; - if(0 == (decoder->private_->seek_table.data.seek_table.points = (FLAC__StreamMetadata_SeekPoint*)malloc(decoder->private_->seek_table.data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint)))) { + /* use realloc since we may pass through here several times (e.g. after seeking) */ + if(0 == (decoder->private_->seek_table.data.seek_table.points = (FLAC__StreamMetadata_SeekPoint*)realloc(decoder->private_->seek_table.data.seek_table.points, decoder->private_->seek_table.data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint)))) { decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; return false; } diff --git a/src/libFLAC/stream_encoder.c b/src/libFLAC/stream_encoder.c index a1f153b9..db123d8a 100644 --- a/src/libFLAC/stream_encoder.c +++ b/src/libFLAC/stream_encoder.c @@ -506,7 +506,7 @@ FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder) FLAC__stream_encoder_finish(encoder); - if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder) + if(0 != encoder->private_->verify.decoder) FLAC__stream_decoder_delete(encoder->private_->verify.decoder); for(i = 0; i < FLAC__MAX_CHANNELS; i++) { diff --git a/src/metaflac/options.c b/src/metaflac/options.c index 51582641..c3e6549c 100644 --- a/src/metaflac/options.c +++ b/src/metaflac/options.c @@ -294,8 +294,13 @@ void free_options(CommandLineOptions *options) if(0 != options->args.arguments) free(options->args.arguments); - if(0 != options->filenames) + if(0 != options->filenames) { + for(i = 0; i < options->num_files; i++) { + if(0 != options->filenames[i]) + free(options->filenames[i]); + } free(options->filenames); + } } /* diff --git a/src/test_libFLAC/bitbuffer.c b/src/test_libFLAC/bitbuffer.c index afcda560..f28e0c0e 100644 --- a/src/test_libFLAC/bitbuffer.c +++ b/src/test_libFLAC/bitbuffer.c @@ -730,9 +730,17 @@ FLAC__bool test_bitbuffer() } printf("OK\n"); - printf("testing free... OK\n"); + printf("testing free... "); FLAC__bitbuffer_free(bb); FLAC__bitbuffer_free(bbcopy); + printf("OK\n"); + + printf("testing delete... "); + FLAC__bitbuffer_delete(bb); + FLAC__bitbuffer_delete(bb_zero); + FLAC__bitbuffer_delete(bb_one); + FLAC__bitbuffer_delete(bbcopy); + printf("OK\n"); printf("\nPASSED!\n"); return true; diff --git a/src/test_libFLAC/metadata_manip.c b/src/test_libFLAC/metadata_manip.c index fd2bfe5f..1445707c 100644 --- a/src/test_libFLAC/metadata_manip.c +++ b/src/test_libFLAC/metadata_manip.c @@ -482,6 +482,7 @@ static FLAC__bool test_level_1_() return die_("mismatch in min_blocksize"); if(block->data.stream_info.max_blocksize != 576) return die_("mismatch in max_blocksize"); + FLAC__metadata_object_delete(block); if(!FLAC__metadata_simple_iterator_next(iterator)) return die_("forward iterator ended early"); @@ -502,6 +503,7 @@ static FLAC__bool test_level_1_() /* check to see if some basic data matches (c.f. generate_file_()) */ if(block->length != 1234) return die_("bad PADDING length"); + FLAC__metadata_object_delete(block); if(FLAC__metadata_simple_iterator_next(iterator)) return die_("forward iterator returned true but should have returned false"); |