From: Felipe Contreras Date: Thu, 28 Apr 2011 17:43:21 +0000 (+0300) Subject: Coverity fixes X-Git-Tag: 1.3.0pre1~149 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6c8d740c1a0bf01605bdd05fe6765ff841dd082a;p=platform%2Fupstream%2Fflac.git Coverity fixes Signed-off-by: Felipe Contreras --- diff --git a/src/libFLAC/md5.c b/src/libFLAC/md5.c index ac1d2b6..feb816b 100644 --- a/src/libFLAC/md5.c +++ b/src/libFLAC/md5.c @@ -259,7 +259,7 @@ void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx) byteSwap(ctx->buf, 4); memcpy(digest, ctx->buf, 16); - memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ + memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */ if(0 != ctx->internal_buf) { free(ctx->internal_buf); ctx->internal_buf = 0; @@ -408,7 +408,8 @@ FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed))) return false; } - ctx->internal_buf = tmp; + else + ctx->internal_buf = tmp; ctx->capacity = bytes_needed; } diff --git a/src/libFLAC/metadata_iterators.c b/src/libFLAC/metadata_iterators.c index 8bd578e..ac6473e 100644 --- a/src/libFLAC/metadata_iterators.c +++ b/src/libFLAC/metadata_iterators.c @@ -1217,6 +1217,7 @@ static FLAC__bool chain_read_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle han } if(!read_metadata_block_header_cb_(handle, read_cb, &is_last, &type, &length)) { + node_delete_(node); chain->status = FLAC__METADATA_CHAIN_STATUS_READ_ERROR; return false; } @@ -1411,38 +1412,34 @@ static FLAC__bool chain_rewrite_file_(FLAC__Metadata_Chain *chain, const char *t } if(!open_tempfile_(chain->filename, tempfile_path_prefix, &tempfile, &tempfilename, &status)) { chain->status = get_equivalent_status_(status); - cleanup_tempfile_(&tempfile, &tempfilename); - return false; + goto err; } if(!copy_n_bytes_from_file_(f, tempfile, chain->first_offset, &status)) { chain->status = get_equivalent_status_(status); - cleanup_tempfile_(&tempfile, &tempfilename); - return false; + goto err; } /* write the metadata */ for(node = chain->head; node; node = node->next) { if(!write_metadata_block_header_(tempfile, &status, node->data)) { chain->status = get_equivalent_status_(status); - return false; + goto err; } if(!write_metadata_block_data_(tempfile, &status, node->data)) { chain->status = get_equivalent_status_(status); - return false; + goto err; } } /*FLAC__ASSERT(fflush(), ftello() == chain->last_offset);*/ /* copy the file postfix (everything after the metadata) */ if(0 != fseeko(f, chain->last_offset, SEEK_SET)) { - cleanup_tempfile_(&tempfile, &tempfilename); chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR; - return false; + goto err; } if(!copy_remaining_bytes_from_file_(f, tempfile, &status)) { - cleanup_tempfile_(&tempfile, &tempfilename); chain->status = get_equivalent_status_(status); - return false; + goto err; } /* move the tempfile on top of the original */ @@ -1451,6 +1448,11 @@ static FLAC__bool chain_rewrite_file_(FLAC__Metadata_Chain *chain, const char *t return false; return true; + +err: + (void)fclose(f); + cleanup_tempfile_(&tempfile, &tempfilename); + return false; } /* assumes 'handle' is already at beginning of file */ diff --git a/src/share/grabbag/picture.c b/src/share/grabbag/picture.c index bdd0a17..3619f0c 100644 --- a/src/share/grabbag/picture.c +++ b/src/share/grabbag/picture.c @@ -287,8 +287,10 @@ FLAC__StreamMetadata *grabbag__picture_parse_specification(const char *spec, con *error_message = 0; - if(0 == (obj = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PICTURE))) + if(0 == (obj = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PICTURE))) { *error_message = error_messages[0]; + return obj; + } if(strchr(spec, '|')) { /* full format */ const char *p; @@ -363,8 +365,10 @@ FLAC__StreamMetadata *grabbag__picture_parse_specification(const char *spec, con *error_message = error_messages[0]; else { FILE *f = fopen(spec, "rb"); - if(0 == f) + if(0 == f) { *error_message = error_messages[5]; + free(buffer); + } else { if(fread(buffer, 1, size, f) != (size_t)size) *error_message = error_messages[6]; @@ -379,6 +383,9 @@ FLAC__StreamMetadata *grabbag__picture_parse_specification(const char *spec, con else if((obj->data.picture.width == 0 || obj->data.picture.height == 0 || obj->data.picture.depth == 0) && !local__extract_resolution_color_info_(&obj->data.picture)) *error_message = error_messages[4]; } + else { + free(buffer); + } } } } diff --git a/src/share/grabbag/replaygain.c b/src/share/grabbag/replaygain.c index 18360cc..4243796 100644 --- a/src/share/grabbag/replaygain.c +++ b/src/share/grabbag/replaygain.c @@ -505,8 +505,10 @@ static const char *store_to_file_post_(const char *filename, FLAC__Metadata_Chai FLAC__metadata_chain_sort_padding(chain); if(!FLAC__metadata_chain_write(chain, /*use_padding=*/true, preserve_modtime)) { + const char *error; + error = FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]; FLAC__metadata_chain_delete(chain); - return FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]; + return error; } FLAC__metadata_chain_delete(chain);