flac-leaks
authorAnas Nashif <anas.nashif@intel.com>
Thu, 22 Nov 2012 14:31:16 +0000 (06:31 -0800)
committerAnas Nashif <anas.nashif@intel.com>
Thu, 22 Nov 2012 14:31:16 +0000 (06:31 -0800)
src/libFLAC/metadata_iterators.c
src/libFLAC/stream_encoder.c

index 8651c10..a3cc1a8 100644 (file)
@@ -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;
                        }
@@ -1412,11 +1413,13 @@ 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);
+        fclose(f);
                return false;
        }
        if(!copy_n_bytes_from_file_(f, tempfile, chain->first_offset, &status)) {
                chain->status = get_equivalent_status_(status);
                cleanup_tempfile_(&tempfile, &tempfilename);
+        fclose(f);
                return false;
        }
 
@@ -1424,10 +1427,14 @@ static FLAC__bool chain_rewrite_file_(FLAC__Metadata_Chain *chain, const char *t
        for(node = chain->head; node; node = node->next) {
                if(!write_metadata_block_header_(tempfile, &status, node->data)) {
                        chain->status = get_equivalent_status_(status);
+            cleanup_tempfile_(&tempfile, &tempfilename);
+            fclose(f);
                        return false;
                }
                if(!write_metadata_block_data_(tempfile, &status, node->data)) {
                        chain->status = get_equivalent_status_(status);
+            cleanup_tempfile_(&tempfile, &tempfilename);
+            fclose(f);
                        return false;
                }
        }
@@ -1437,10 +1444,12 @@ static FLAC__bool chain_rewrite_file_(FLAC__Metadata_Chain *chain, const char *t
        if(0 != fseeko(f, chain->last_offset, SEEK_SET)) {
                cleanup_tempfile_(&tempfile, &tempfilename);
                chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR;
+        fclose(f);
                return false;
        }
        if(!copy_remaining_bytes_from_file_(f, tempfile, &status)) {
                cleanup_tempfile_(&tempfile, &tempfilename);
+        fclose(f);
                chain->status = get_equivalent_status_(status);
                return false;
        }
index a208b87..6e79373 100644 (file)
@@ -1004,10 +1004,12 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
                /*
                 * Now set up a stream decoder for verification
                 */
-               encoder->private_->verify.decoder = FLAC__stream_decoder_new();
                if(0 == encoder->private_->verify.decoder) {
-                       encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
-                       return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
+            encoder->private_->verify.decoder = FLAC__stream_decoder_new();
+            if(0 == encoder->private_->verify.decoder) {
+                           encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
+                           return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
+            }
                }
 
                if(FLAC__stream_decoder_init_stream(encoder->private_->verify.decoder, verify_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, verify_write_callback_, verify_metadata_callback_, verify_error_callback_, /*client_data=*/encoder) != FLAC__STREAM_DECODER_INIT_STATUS_OK) {