Skip to content

Commit

Permalink
clean up more memory leaks reported by valgrind
Browse files Browse the repository at this point in the history
  • Loading branch information
kriemo committed Sep 15, 2023
1 parent 5a095a6 commit 3d3c621
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/plp.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ static int store_counts(PLP_DATA pd, pcounts* pc, const char* ctig,
nv = kh_value((pc + i)->pc->var, k);
vf = (double) nv / (pc + i)->pc->total;
if (vf < conf->min_af) {
char *key = (char *)kh_key((pc + i)->pc->var, k);
free(key);
kh_del(str2intmap, (pc + i)->pc->var, k);
}
}
Expand All @@ -387,6 +389,8 @@ static int store_counts(PLP_DATA pd, pcounts* pc, const char* ctig,
nv = kh_value((pc + i)->mc->var, k);
vf = (double) nv / (pc + i)->mc->total;
if (vf < conf->min_af) {
char *key = (char *)kh_key((pc + i)->mc->var, k);
free(key);
kh_del(str2intmap, (pc + i)->mc->var, k);
}
}
Expand Down Expand Up @@ -692,12 +696,15 @@ static int run_pileup(char** cbampaths, char** cindexes,
idx = sam_index_load2(data[i]->fp, cbampaths[i], cindexes[i]) ;

if (idx == NULL) {
bam_hdr_destroy(h_tmp);
REprintf("[raer internal] fail to load bamfile index for %s\n", cbampaths[i]);
ret = -1;
goto fail;
}

if ((data[i]->iter=sam_itr_querys(idx, h_tmp, conf->reg)) == 0) {
bam_hdr_destroy(h_tmp);
hts_idx_destroy(idx);
REprintf("[raer internal] fail to parse region '%s' with %s\n", conf->reg, cbampaths[i]);
ret = -1;
goto fail;
Expand Down Expand Up @@ -899,7 +906,7 @@ static int run_pileup(char** cbampaths, char** cindexes,
}

fail:
if (ret >= 0) finish_PLP_DATA(pd);
finish_PLP_DATA(pd);

if(iter) bam_mplp_destroy(iter);
if(h) bam_hdr_destroy(h);
Expand Down Expand Up @@ -927,15 +934,17 @@ static int run_pileup(char** cbampaths, char** cindexes,
if (pall) {
R_Free(pall->p_ref_pos);
R_Free(pall->p_alt_pos);
R_Free(pall->m_ref_pos);
R_Free(pall->m_alt_pos);
R_Free(pall->m_alt_pos);
R_Free(pall->s);
R_Free(pall);
}

if(plpc) R_Free(plpc);
if(pd->fps) R_Free(pd->fps);
if(pd->pdat) R_Free(pd->pdat);
if(pd->sdat) R_Free(pd->sdat);
if(pd) R_Free(pd);
if(site_stats) R_Free(site_stats);

return ret;
Expand Down
1 change: 1 addition & 0 deletions src/sc-plp.c
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ static int write_all_sites(sc_mplp_conf_t* conf) {
pld->alt);

}
regitr_destroy(itr);
return (1);
}

Expand Down

0 comments on commit 3d3c621

Please sign in to comment.