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.
This commit is contained in:
parent
1972a97813
commit
6a5caf764f
|
|
@ -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));
|
bwt->decodeTable = (unsigned*)calloc(DNA_OCC_CNT_TABLE_SIZE_IN_WORD, sizeof(unsigned int));
|
||||||
GenerateDNAOccCountTable(bwt->decodeTable);
|
GenerateDNAOccCountTable(bwt->decodeTable);
|
||||||
} else {
|
} else {
|
||||||
|
// FIXME Prevent BWTFree() from freeing decodeTable in this case
|
||||||
bwt->decodeTable = decodeTable;
|
bwt->decodeTable = decodeTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1538,6 +1539,8 @@ BWTInc *BWTIncConstructFromPacked(const char *inputFileName, bgint_t initialMaxB
|
||||||
(long)bwtInc->numberOfIterationDone, (long)processedTextLength);
|
(long)bwtInc->numberOfIterationDone, (long)processedTextLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fclose(packedFile);
|
||||||
return bwtInc;
|
return bwtInc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1545,8 +1548,6 @@ void BWTFree(BWT *bwt)
|
||||||
{
|
{
|
||||||
if (bwt == 0) return;
|
if (bwt == 0) return;
|
||||||
free(bwt->cumulativeFreq);
|
free(bwt->cumulativeFreq);
|
||||||
free(bwt->bwtCode);
|
|
||||||
free(bwt->occValue);
|
|
||||||
free(bwt->occValueMajor);
|
free(bwt->occValueMajor);
|
||||||
free(bwt->decodeTable);
|
free(bwt->decodeTable);
|
||||||
free(bwt);
|
free(bwt);
|
||||||
|
|
@ -1555,8 +1556,10 @@ void BWTFree(BWT *bwt)
|
||||||
void BWTIncFree(BWTInc *bwtInc)
|
void BWTIncFree(BWTInc *bwtInc)
|
||||||
{
|
{
|
||||||
if (bwtInc == 0) return;
|
if (bwtInc == 0) return;
|
||||||
free(bwtInc->bwt);
|
BWTFree(bwtInc->bwt);
|
||||||
free(bwtInc->workingMemory);
|
free(bwtInc->workingMemory);
|
||||||
|
free(bwtInc->cumulativeCountInCurrentBuild);
|
||||||
|
free(bwtInc->packedShift);
|
||||||
free(bwtInc);
|
free(bwtInc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue