Commit 651a936
Memory leak iterating multiple queries over cram
The following code consumes memory indefinitely. Memory leak is gone once the change is applied.
Steps:
1. build htslib
2. compile test.c with:
gcc -O0 -ggdb -I htslib/install/include test.c -L htslib/install/lib/ -l:libhts.a -lz -lpthread -llzma -lbz2
3. run ./a.out some.cram chr1
4. watch virtual memory going up in top
5. apply patch, rebuild test.c, notice virtual memory does not change
test.c:
```c++
int main(int argc,char** argv)
{
hts_itr_t *iter=NULL;
hts_idx_t *idx=NULL;
samFile *in = NULL;
bam1_t *b= NULL;
bam_hdr_t *header = NULL;
if(argc!=3) return -1;
in = sam_open(argv[1], "r");
if(in==NULL) return -1;
if ((header = sam_hdr_read(in)) == 0) return -1;
idx = sam_index_load(in, argv[1]);
if(idx==NULL) return -1;
b = bam_init1();
fputs("reading\n",stdout);
do
{
if (iter) hts_itr_destroy(iter);
iter = sam_itr_querys(idx, header, argv[2]);
if(!iter) return -1;
// fputs("DO STUFF\n",stdout);
}
while (sam_itr_next(in, iter, b) >= 0);
fputs("done reading\n",stdout);
hts_itr_destroy(iter);
bam_destroy1(b);
hts_idx_destroy(idx);
bam_hdr_destroy(header);
sam_close(in);
return 0;
}
```1 parent 816a220 commit 651a936
1 file changed
+22
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2747 | 2747 | | |
2748 | 2748 | | |
2749 | 2749 | | |
2750 | | - | |
2751 | | - | |
2752 | | - | |
2753 | | - | |
| 2750 | + | |
| 2751 | + | |
| 2752 | + | |
| 2753 | + | |
| 2754 | + | |
| 2755 | + | |
| 2756 | + | |
| 2757 | + | |
| 2758 | + | |
| 2759 | + | |
| 2760 | + | |
2754 | 2761 | | |
2755 | 2762 | | |
2756 | 2763 | | |
| |||
2885 | 2892 | | |
2886 | 2893 | | |
2887 | 2894 | | |
| 2895 | + | |
2888 | 2896 | | |
2889 | 2897 | | |
2890 | 2898 | | |
| |||
3129 | 3137 | | |
3130 | 3138 | | |
3131 | 3139 | | |
3132 | | - | |
3133 | | - | |
3134 | | - | |
| 3140 | + | |
| 3141 | + | |
| 3142 | + | |
| 3143 | + | |
| 3144 | + | |
| 3145 | + | |
3135 | 3146 | | |
3136 | 3147 | | |
3137 | 3148 | | |
3138 | 3149 | | |
3139 | | - | |
| 3150 | + | |
| 3151 | + | |
| 3152 | + | |
| 3153 | + | |
3140 | 3154 | | |
3141 | 3155 | | |
3142 | 3156 | | |
| |||
0 commit comments