mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
fix memory leaks found with valgrind
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user