Skip to content

Commit

Permalink
Fix heap cleanup-on-fail in bam_merge_simple
Browse files Browse the repository at this point in the history
Bam records in the heap could have come from a file or an in-memory
block.  Only the ones from files should be freed.  Fix an incorrect
assumption that the first entries all came from files.  Instead,
look in heap[i].i to see if the bam record came from a file or
an in-memory block.
  • Loading branch information
daviesrob committed Nov 19, 2019
1 parent ef8e24f commit b59c80f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bam_sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,10 @@ static int bam_merge_simple(int by_qname, char *sort_tag, const char *out,
fail:
for (i = 0; i < n; i++) {
if (fp && fp[i]) sam_close(fp[i]);
if (heap && heap[i].entry.bam_record) bam_destroy1(heap[i].entry.bam_record);
}
for (i = 0; i < heap_size; i++) {
if (heap && heap[i].i < n && heap[i].entry.bam_record)
bam_destroy1(heap[i].entry.bam_record);
}
free(fp);
free(heap);
Expand Down

0 comments on commit b59c80f

Please sign in to comment.