flac-leaks
[platform/upstream/flac.git] / src / libFLAC / metadata_iterators.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;
        }