Memory and fd leak fixes - ID: 3436668

http://sourceforge.net/tracker/?func=detail&aid=3436668&group_id=13478&atid=313478
This commit is contained in:
Erik de Castro Lopo 2012-02-04 17:30:57 +11:00
parent 0fe9767ebb
commit 8f95634bd9
4 changed files with 10 additions and 1 deletions

View File

@ -1723,6 +1723,7 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
else { else {
if(!memcmp(lookahead, "ID3", 3)) { if(!memcmp(lookahead, "ID3", 3)) {
flac__utils_printf(stderr, 1, "ERROR: input file %s has an ID3v2 tag\n", infilename); flac__utils_printf(stderr, 1, "ERROR: input file %s has an ID3v2 tag\n", infilename);
conditional_fclose(encode_infile);
return 1; return 1;
} }
else if(!memcmp(lookahead, "RIFF", 4) && !memcmp(lookahead+8, "WAVE", 4)) else if(!memcmp(lookahead, "RIFF", 4) && !memcmp(lookahead+8, "WAVE", 4))
@ -1932,6 +1933,8 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
if(0 == encode_options.format_options.iff.foreign_metadata) { if(0 == encode_options.format_options.iff.foreign_metadata) {
flac__utils_printf(stderr, 1, "ERROR: creating foreign metadata object\n"); flac__utils_printf(stderr, 1, "ERROR: creating foreign metadata object\n");
conditional_fclose(encode_infile); conditional_fclose(encode_infile);
if(internal_outfilename != 0)
free(internal_outfilename);
return 1; return 1;
} }
} }

View File

@ -196,6 +196,8 @@ FLAC__bool export_cs_to(const char *filename, const FLAC__StreamMetadata *cueshe
reflen = strlen(filename) + 7 + 1; reflen = strlen(filename) + 7 + 1;
if(0 == (ref = malloc(reflen))) { if(0 == (ref = malloc(reflen))) {
fprintf(stderr, "%s: ERROR: allocating memory\n", filename); fprintf(stderr, "%s: ERROR: allocating memory\n", filename);
if(f != stdout)
fclose(f);
return false; return false;
} }

View File

@ -163,6 +163,8 @@ FLAC__bool export_pic_to(const char *filename, const FLAC__StreamMetadata *pictu
if(fwrite(picture->data.picture.data, 1, len, f) != len) { if(fwrite(picture->data.picture.data, 1, len, f) != len) {
fprintf(stderr, "%s: ERROR: writing PICTURE data to file\n", filename); fprintf(stderr, "%s: ERROR: writing PICTURE data to file\n", filename);
if(f != stdout)
fclose(f);
return false; return false;
} }

View File

@ -352,8 +352,10 @@ static bool write_chain_(FLAC::Metadata::Chain &chain, bool use_padding, bool pr
FILE *file = fopen(filename, "r+b"); FILE *file = fopen(filename, "r+b");
if(0 == file) if(0 == file)
return false; /*@@@@ chain status still says OK though */ return false; /*@@@@ chain status still says OK though */
if(!chain.write(use_padding, (::FLAC__IOHandle)file, callbacks)) if(!chain.write(use_padding, (::FLAC__IOHandle)file, callbacks)) {
fclose(file);
return false; return false;
}
fclose(file); fclose(file);
} }
} }