fix minor leaks

This commit is contained in:
Josh Coalson 2007-02-13 02:05:19 +00:00
parent c0f51e77bc
commit 147dbe2baa
6 changed files with 18 additions and 25 deletions

View File

@ -19,8 +19,6 @@
* 3 : unknown encoding (but still converted, using '?')
*/
void convert_set_charset(const char *charset);
int utf8_encode(const char *from, char **to);
int utf8_decode(const char *from, char **to);

View File

@ -1500,7 +1500,7 @@ int flac__encode_flac(FILE *infile, off_t infilesize, const char *infilename, co
/* (channel mask will get copied over from the source VORBIS_COMMENT if it exists) */
if(!EncoderSession_init_encoder(&encoder_session, options.common, /*channel_mask=*/0, decoder_data.metadata_blocks[0]->data.stream_info.channels, decoder_data.metadata_blocks[0]->data.stream_info.bits_per_sample, decoder_data.metadata_blocks[0]->data.stream_info.sample_rate, &decoder_data))
return EncoderSession_finish_error(&encoder_session);
goto fubar2; /*@@@ yuck */
/*
* have to wait until the FLAC encoder is set up for writing
@ -1542,12 +1542,12 @@ int flac__encode_flac(FILE *infile, off_t infilesize, const char *infilename, co
retval = EncoderSession_finish_ok(&encoder_session, -1, -1);
/* have to wail until encoder is completely finished before deleting because of the final step of writing the seekpoint offsets */
for(i = 0; i < decoder_data.num_metadata_blocks; i++)
free(decoder_data.metadata_blocks[i]);
FLAC__metadata_object_delete(decoder_data.metadata_blocks[i]);
return retval;
fubar2:
for(i = 0; i < decoder_data.num_metadata_blocks; i++)
free(decoder_data.metadata_blocks[i]);
FLAC__metadata_object_delete(decoder_data.metadata_blocks[i]);
fubar1:
FLAC__stream_decoder_delete(decoder);
return EncoderSession_finish_error(&encoder_session);

View File

@ -231,23 +231,17 @@ int iconvert(const char *fromcode, const char *tocode,
const char *from, size_t fromlen,
char **to, size_t *tolen);
static char *current_charset = 0; /* means "US-ASCII" */
void convert_set_charset(const char *charset)
static const char *current_charset(void)
{
const char *c = 0;
#ifdef HAVE_LANGINFO_CODESET
if (!charset)
charset = nl_langinfo(CODESET);
c = nl_langinfo(CODESET);
#endif
if (!charset)
charset = getenv("CHARSET");
if (!c)
c = getenv("CHARSET");
free(current_charset);
current_charset = 0;
if (charset && *charset)
current_charset = strdup(charset);
return c? c : "US-ASCII";
}
static int convert_buffer(const char *fromcode, const char *tocode,
@ -300,20 +294,14 @@ int utf8_encode(const char *from, char **to)
{
char *charset;
if (!current_charset)
convert_set_charset(0);
charset = current_charset ? current_charset : "US-ASCII";
return convert_string(charset, "UTF-8", from, to, '#');
return convert_string(current_charset(), "UTF-8", from, to, '#');
}
int utf8_decode(const char *from, char **to)
{
char *charset;
if (!current_charset)
convert_set_charset(0);
charset = current_charset ? current_charset : "US-ASCII";
return convert_string("UTF-8", charset, from, to, '?');
return convert_string("UTF-8", current_charset(), from, to, '?');
}
#endif

View File

@ -600,6 +600,8 @@ static bool generate_file_(bool include_extras, bool is_ogg)
return die_("creating the encoded file");
free(vorbiscomment.data.vorbis_comment.vendor_string.entry);
free(picture.data.picture.mime_type);
free(picture.data.picture.description);
free(picture.data.picture.data);
return true;

View File

@ -610,6 +610,10 @@ static FLAC__bool generate_file_(FLAC__bool include_extras, FLAC__bool is_ogg)
free(vorbiscomment.data.vorbis_comment.vendor_string.entry);
free(picture.data.picture.mime_type);
free(picture.data.picture.description);
free(picture.data.picture.data);
if(!include_extras)
FLAC__metadata_object_delete(cuesheet);
return true;
}

View File

@ -304,6 +304,7 @@ static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t fi
return die_s_("FLAC__stream_decoder_finish() FAILED", decoder);
}
FLAC__stream_decoder_delete(decoder);
printf("\nPASSED!\n");
return true;