fix memory leaks found with valgrind

This commit is contained in:
Josh Coalson
2002-12-04 07:01:37 +00:00
parent 44ca9fedaa
commit 4fa90599fe
7 changed files with 41 additions and 12 deletions

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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++) {