Skip to content

Commit

Permalink
Fixed BWTIncFree() memory leaks
Browse files Browse the repository at this point in the history
[Based on PR lh3#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.
  • Loading branch information
GwenIves authored and jmarshall committed May 12, 2017
1 parent 1972a97 commit 6a5caf7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions bwt_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -1538,15 +1539,15 @@ BWTInc *BWTIncConstructFromPacked(const char *inputFileName, bgint_t initialMaxB
(long)bwtInc->numberOfIterationDone, (long)processedTextLength);
}
}

fclose(packedFile);
return bwtInc;
}

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);
Expand All @@ -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);
}

Expand Down

0 comments on commit 6a5caf7

Please sign in to comment.