From 6a5caf764f4123b49fff8504291c72c372705514 Mon Sep 17 00:00:00 2001 From: Gwen Ives Date: Tue, 9 Dec 2014 10:24:46 +0100 Subject: [PATCH] Fixed BWTIncFree() memory leaks [Based on PR #37 with the additions below.] Don't free non-malloced items in BWTFree(). If BWTCreate() is ever called with a non-NULL decodeTable, BWTFree() will need to not free decodeTable -- see FIXME comment. Close packedFile in BWTIncConstructFromPacked() in the normal case. Ignore it in error cases, as they immediately call exit() anyway. --- bwt_gen.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bwt_gen.c b/bwt_gen.c index 76f28c9..5b563d0 100644 --- a/bwt_gen.c +++ b/bwt_gen.c @@ -338,6 +338,7 @@ BWT *BWTCreate(const bgint_t textLength, unsigned int *decodeTable) bwt->decodeTable = (unsigned*)calloc(DNA_OCC_CNT_TABLE_SIZE_IN_WORD, sizeof(unsigned int)); GenerateDNAOccCountTable(bwt->decodeTable); } else { + // FIXME Prevent BWTFree() from freeing decodeTable in this case bwt->decodeTable = decodeTable; } @@ -1538,6 +1539,8 @@ BWTInc *BWTIncConstructFromPacked(const char *inputFileName, bgint_t initialMaxB (long)bwtInc->numberOfIterationDone, (long)processedTextLength); } } + + fclose(packedFile); return bwtInc; } @@ -1545,8 +1548,6 @@ void BWTFree(BWT *bwt) { if (bwt == 0) return; free(bwt->cumulativeFreq); - free(bwt->bwtCode); - free(bwt->occValue); free(bwt->occValueMajor); free(bwt->decodeTable); free(bwt); @@ -1555,8 +1556,10 @@ void BWTFree(BWT *bwt) void BWTIncFree(BWTInc *bwtInc) { if (bwtInc == 0) return; - free(bwtInc->bwt); + BWTFree(bwtInc->bwt); free(bwtInc->workingMemory); + free(bwtInc->cumulativeCountInCurrentBuild); + free(bwtInc->packedShift); free(bwtInc); }