From 826fbccf115b0ed46502e70e230e5e942dcddbd2 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Fri, 7 Sep 2018 14:05:45 +0200 Subject: [PATCH] Fixed memory leaks in new decoder --- lib/include/srslte/phy/fec/turbodecoder_win.h | 8 +++++--- lib/src/phy/fec/turbodecoder_gen.c | 8 +++++--- lib/src/phy/fec/turbodecoder_sse.c | 14 ++++++++------ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/include/srslte/phy/fec/turbodecoder_win.h b/lib/include/srslte/phy/fec/turbodecoder_win.h index c4941278d..347e3ecc2 100644 --- a/lib/include/srslte/phy/fec/turbodecoder_win.h +++ b/lib/include/srslte/phy/fec/turbodecoder_win.h @@ -603,10 +603,12 @@ int MAKE_FUNC(init)(void **hh, uint32_t max_long_cb) void MAKE_FUNC(free)(void *hh) { MAKE_TYPE *h = (MAKE_TYPE*) hh; - if (h->beta) { - free(h->beta); + if (h) { + if (h->beta) { + free(h->beta); + } + free(h); } - bzero(h, sizeof(MAKE_TYPE)); } void MAKE_FUNC(dec)(void *hh, llr_t *input, llr_t *app, llr_t *parity, llr_t *output, uint32_t long_cb) diff --git a/lib/src/phy/fec/turbodecoder_gen.c b/lib/src/phy/fec/turbodecoder_gen.c index 4cabe05ce..b7d67dae0 100644 --- a/lib/src/phy/fec/turbodecoder_gen.c +++ b/lib/src/phy/fec/turbodecoder_gen.c @@ -215,10 +215,12 @@ int tdec_gen_init(void **hh, uint32_t max_long_cb) void tdec_gen_free(void *hh) { tdec_gen_t *h = (tdec_gen_t*) hh; - if (h->beta) { - free(h->beta); + if (h) { + if (h->beta) { + free(h->beta); + } + free(h); } - bzero(h, sizeof(tdec_gen_t)); } void tdec_gen_dec(void *hh, int16_t *input, int16_t *app, int16_t *parity, int16_t *output, uint32_t long_cb) diff --git a/lib/src/phy/fec/turbodecoder_sse.c b/lib/src/phy/fec/turbodecoder_sse.c index 4b1c2486e..e5724af45 100644 --- a/lib/src/phy/fec/turbodecoder_sse.c +++ b/lib/src/phy/fec/turbodecoder_sse.c @@ -379,13 +379,15 @@ void tdec_sse_free(void *hh) { tdec_sse_t *h = (tdec_sse_t*) hh; - if (h->alpha) { - free(h->alpha); - } - if (h->branch) { - free(h->branch); + if (h) { + if (h->alpha) { + free(h->alpha); + } + if (h->branch) { + free(h->branch); + } + free(h); } - bzero(h, sizeof(tdec_sse_t)); } /* Runs one instance of a decoder */