Skip to content

Commit

Permalink
Fix memory and FD leaks
Browse files Browse the repository at this point in the history
Patch derived from SF#3436668, courtesy of Ville Skyttä.
  • Loading branch information
toofishes committed Mar 23, 2012
1 parent e76e99e commit 2044ab6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/flac/main.c
Expand Up @@ -1723,6 +1723,7 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
else {
if(!memcmp(lookahead, "ID3", 3)) {
flac__utils_printf(stderr, 1, "ERROR: input file %s has an ID3v2 tag\n", infilename);
conditional_fclose(encode_infile);
return 1;
}
else if(!memcmp(lookahead, "RIFF", 4) && !memcmp(lookahead+8, "WAVE", 4))
Expand Down Expand Up @@ -1932,6 +1933,7 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
if(0 == encode_options.format_options.iff.foreign_metadata) {
flac__utils_printf(stderr, 1, "ERROR: creating foreign metadata object\n");
conditional_fclose(encode_infile);
free(internal_outfilename);
return 1;
}
}
Expand Down Expand Up @@ -1989,8 +1991,7 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
if(retval == 0 && option_values.delete_input && strcmp(infilename, "-") && internal_outfilename == 0)
unlink(infilename);

if(internal_outfilename != 0)
free(internal_outfilename);
free(internal_outfilename);

return retval;
}
Expand Down
2 changes: 2 additions & 0 deletions src/metaflac/operations_shorthand_cuesheet.c
Expand Up @@ -199,6 +199,8 @@ FLAC__bool export_cs_to(const char *filename, const FLAC__StreamMetadata *cueshe
reflen = strlen(filename) + 7 + 1;
if(0 == (ref = malloc(reflen))) {
fprintf(stderr, "%s: ERROR: allocating memory\n", filename);
if(f != stdout)
fclose(f);
return false;
}

Expand Down
4 changes: 3 additions & 1 deletion src/test_libFLAC++/metadata_manip.cpp
Expand Up @@ -360,8 +360,10 @@ static bool write_chain_(FLAC::Metadata::Chain &chain, bool use_padding, bool pr
FILE *file = fopen(filename, "r+b");
if(0 == file)
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;
}
fclose(file);
}
}
Expand Down

0 comments on commit 2044ab6

Please sign in to comment.