From 2392e54fe2953b655f5fc71da527ebd78d90dae4 Mon Sep 17 00:00:00 2001 From: Heng Li Date: Wed, 4 Aug 2021 17:07:00 -0400 Subject: [PATCH] r1089: fixed an unusual memory leak (#749) This is more apparent when there are many candidate chains. Although only a small numbers of them are extended, they are still occupying memory. A realloc() solves this problem. This is a long existiing issue. --- main.c | 2 +- map.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index ded53cc..b3d2e80 100644 --- a/main.c +++ b/main.c @@ -7,7 +7,7 @@ #include "mmpriv.h" #include "ketopt.h" -#define MM_VERSION "2.21-dev-r1087-dirty" +#define MM_VERSION "2.21-dev-r1089-dirty" #ifdef __linux__ #include diff --git a/map.c b/map.c index 1999c10..15d1b7b 100644 --- a/map.c +++ b/map.c @@ -336,6 +336,7 @@ void mm_map_frag(const mm_idx_t *mi, int n_segs, const int *qlens, const char ** if (n_segs == 1) { // uni-segment regs0 = align_regs(opt, mi, b->km, qlens[0], seqs[0], &n_regs0, regs0, a); + regs0 = (mm_reg1_t*)realloc(regs0, sizeof(*regs0) * n_regs0); mm_set_mapq(b->km, n_regs0, regs0, opt->min_chain_score, opt->a, rep_len, is_sr); n_regs[0] = n_regs0, regs[0] = regs0; } else { // multi-segment