Fix memory leak in mappy.aligner.map.
This commit is contained in:
parent
e026e18439
commit
238b6bb3ea
|
|
@ -188,23 +188,30 @@ cdef class Aligner:
|
||||||
_seq2 = seq2 if isinstance(seq2, bytes) else seq2.encode()
|
_seq2 = seq2 if isinstance(seq2, bytes) else seq2.encode()
|
||||||
regs = cmappy.mm_map_aux(self._idx, _seq, _seq2, &n_regs, b._b, &map_opt)
|
regs = cmappy.mm_map_aux(self._idx, _seq, _seq2, &n_regs, b._b, &map_opt)
|
||||||
|
|
||||||
for i in range(n_regs):
|
try:
|
||||||
cmappy.mm_reg2hitpy(self._idx, ®s[i], &h)
|
i = 0
|
||||||
cigar, _cs, _MD = [], '', ''
|
while i < n_regs:
|
||||||
for k in range(h.n_cigar32): # convert the 32-bit CIGAR encoding to Python array
|
cmappy.mm_reg2hitpy(self._idx, ®s[i], &h)
|
||||||
c = h.cigar32[k]
|
cigar, _cs, _MD = [], '', ''
|
||||||
cigar.append([c>>4, c&0xf])
|
for k in range(h.n_cigar32): # convert the 32-bit CIGAR encoding to Python array
|
||||||
if cs or MD: # generate the cs and/or the MD tag, if requested
|
c = h.cigar32[k]
|
||||||
if cs:
|
cigar.append([c>>4, c&0xf])
|
||||||
l_cs_str = cmappy.mm_gen_cs(km, &cs_str, &m_cs_str, self._idx, ®s[i], _seq, 1)
|
if cs or MD: # generate the cs and/or the MD tag, if requested
|
||||||
_cs = cs_str[:l_cs_str] if isinstance(cs_str, str) else cs_str[:l_cs_str].decode()
|
if cs:
|
||||||
if MD:
|
l_cs_str = cmappy.mm_gen_cs(km, &cs_str, &m_cs_str, self._idx, ®s[i], _seq, 1)
|
||||||
l_cs_str = cmappy.mm_gen_MD(km, &cs_str, &m_cs_str, self._idx, ®s[i], _seq)
|
_cs = cs_str[:l_cs_str] if isinstance(cs_str, str) else cs_str[:l_cs_str].decode()
|
||||||
_MD = cs_str[:l_cs_str] if isinstance(cs_str, str) else cs_str[:l_cs_str].decode()
|
if MD:
|
||||||
yield Alignment(h.ctg, h.ctg_len, h.ctg_start, h.ctg_end, h.strand, h.qry_start, h.qry_end, h.mapq, cigar, h.is_primary, h.mlen, h.blen, h.NM, h.trans_strand, h.seg_id, _cs, _MD)
|
l_cs_str = cmappy.mm_gen_MD(km, &cs_str, &m_cs_str, self._idx, ®s[i], _seq)
|
||||||
cmappy.mm_free_reg1(®s[i])
|
_MD = cs_str[:l_cs_str] if isinstance(cs_str, str) else cs_str[:l_cs_str].decode()
|
||||||
free(regs)
|
yield Alignment(h.ctg, h.ctg_len, h.ctg_start, h.ctg_end, h.strand, h.qry_start, h.qry_end, h.mapq, cigar, h.is_primary, h.mlen, h.blen, h.NM, h.trans_strand, h.seg_id, _cs, _MD)
|
||||||
free(cs_str)
|
cmappy.mm_free_reg1(®s[i])
|
||||||
|
i += 1
|
||||||
|
finally:
|
||||||
|
while i < n_regs:
|
||||||
|
cmappy.mm_free_reg1(®s[i])
|
||||||
|
i += 1
|
||||||
|
free(regs)
|
||||||
|
free(cs_str)
|
||||||
|
|
||||||
def seq(self, str name, int start=0, int end=0x7fffffff):
|
def seq(self, str name, int start=0, int end=0x7fffffff):
|
||||||
cdef int l
|
cdef int l
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue