提交 29278327 编写于 作者: dengyihao's avatar dengyihao

fix mem leak

上级 210db65b
...@@ -803,6 +803,7 @@ void fstBuilderDestroy(FstBuilder *b) { ...@@ -803,6 +803,7 @@ void fstBuilderDestroy(FstBuilder *b) {
fstCountingWriterDestroy(b->wrt); fstCountingWriterDestroy(b->wrt);
fstUnFinishedNodesDestroy(b->unfinished); fstUnFinishedNodesDestroy(b->unfinished);
fstRegistryDestroy(b->registry); fstRegistryDestroy(b->registry);
fstSliceDestroy(&b->last);
free(b); free(b);
} }
...@@ -869,13 +870,15 @@ OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup) { ...@@ -869,13 +870,15 @@ OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup) {
void fstBuilderCompileFrom(FstBuilder *b, uint64_t istate) { void fstBuilderCompileFrom(FstBuilder *b, uint64_t istate) {
CompiledAddr addr = NONE_ADDRESS; CompiledAddr addr = NONE_ADDRESS;
while (istate + 1 < FST_UNFINISHED_NODES_LEN(b->unfinished)) { while (istate + 1 < FST_UNFINISHED_NODES_LEN(b->unfinished)) {
FstBuilderNode *n = NULL; FstBuilderNode *bn = NULL;
if (addr == NONE_ADDRESS) { if (addr == NONE_ADDRESS) {
n = fstUnFinishedNodesPopEmpty(b->unfinished); bn = fstUnFinishedNodesPopEmpty(b->unfinished);
} else { } else {
n = fstUnFinishedNodesPopFreeze(b->unfinished, addr); bn = fstUnFinishedNodesPopFreeze(b->unfinished, addr);
} }
addr = fstBuilderCompile(b, n); addr = fstBuilderCompile(b, bn);
fstBuilderNodeDestroy(bn);
assert(addr != NONE_ADDRESS); assert(addr != NONE_ADDRESS);
//fstBuilderNodeDestroy(n); //fstBuilderNodeDestroy(n);
} }
...@@ -910,6 +913,7 @@ void* fstBuilderInsertInner(FstBuilder *b) { ...@@ -910,6 +913,7 @@ void* fstBuilderInsertInner(FstBuilder *b) {
fstBuilderCompileFrom(b, 0); fstBuilderCompileFrom(b, 0);
FstBuilderNode *rootNode = fstUnFinishedNodesPopRoot(b->unfinished); FstBuilderNode *rootNode = fstUnFinishedNodesPopRoot(b->unfinished);
CompiledAddr rootAddr = fstBuilderCompile(b, rootNode); CompiledAddr rootAddr = fstBuilderCompile(b, rootNode);
fstBuilderNodeDestroy(rootNode);
char buf64[8] = {0}; char buf64[8] = {0};
...@@ -1026,7 +1030,10 @@ Fst* fstCreate(FstSlice *slice) { ...@@ -1026,7 +1030,10 @@ Fst* fstCreate(FstSlice *slice) {
fst->meta->ty = type; fst->meta->ty = type;
fst->meta->len = fstLen; fst->meta->len = fstLen;
fst->meta->checkSum = checkSum; fst->meta->checkSum = checkSum;
fst->data = slice;
FstSlice *s = calloc(1, sizeof(FstSlice));
*s = fstSliceCopy(slice, 0, FST_SLICE_LEN(slice));
fst->data = s;
return fst; return fst;
...@@ -1038,7 +1045,8 @@ FST_CREAT_FAILED: ...@@ -1038,7 +1045,8 @@ FST_CREAT_FAILED:
void fstDestroy(Fst *fst) { void fstDestroy(Fst *fst) {
if (fst) { if (fst) {
free(fst->meta); free(fst->meta);
fstNodeDestroy(fst->root); fstSliceDestroy(fst->data);
free(fst->data);
} }
free(fst); free(fst);
} }
...@@ -1048,6 +1056,9 @@ bool fstGet(Fst *fst, FstSlice *b, Output *out) { ...@@ -1048,6 +1056,9 @@ bool fstGet(Fst *fst, FstSlice *b, Output *out) {
Output tOut = 0; Output tOut = 0;
int32_t len; int32_t len;
uint8_t *data = fstSliceData(b, &len); uint8_t *data = fstSliceData(b, &len);
SArray *nodes = (SArray *)taosArrayInit(len, sizeof(FstNode *));
taosArrayPush(nodes, &root);
for (uint32_t i = 0; i < len; i++) { for (uint32_t i = 0; i < len; i++) {
uint8_t inp = data[i]; uint8_t inp = data[i];
Output res = 0; Output res = 0;
...@@ -1059,12 +1070,22 @@ bool fstGet(Fst *fst, FstSlice *b, Output *out) { ...@@ -1059,12 +1070,22 @@ bool fstGet(Fst *fst, FstSlice *b, Output *out) {
fstNodeGetTransitionAt(root, res, &trn); fstNodeGetTransitionAt(root, res, &trn);
tOut += trn.out; tOut += trn.out;
root = fstGetNode(fst, trn.addr); root = fstGetNode(fst, trn.addr);
taosArrayPush(nodes, &root);
//fstNodeDestroy(root);
} }
if (!FST_NODE_IS_FINAL(root)) { if (!FST_NODE_IS_FINAL(root)) {
return false; return false;
} else { } else {
tOut = tOut + FST_NODE_FINAL_OUTPUT(root); tOut = tOut + FST_NODE_FINAL_OUTPUT(root);
} }
for (size_t i = 0; i < taosArrayGetSize(nodes); i++) {
FstNode **node = (FstNode **)taosArrayGet(nodes, i);
fstNodeDestroy(*node);
}
taosArrayDestroy(nodes);
fst->root = NULL;
*out = tOut; *out = tOut;
return true; return true;
...@@ -1228,6 +1249,7 @@ bool streamWithStateSeekMin(StreamWithState *sws, FstBoundWithData *min) { ...@@ -1228,6 +1249,7 @@ bool streamWithStateSeekMin(StreamWithState *sws, FstBoundWithData *min) {
taosArrayPush(sws->stack, &s); taosArrayPush(sws->stack, &s);
out += trn.out; out += trn.out;
node = fstGetNode(sws->fst, trn.addr); node = fstGetNode(sws->fst, trn.addr);
fstNodeDestroy(node);
} else { } else {
// This is a little tricky. We're in this case if the // This is a little tricky. We're in this case if the
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册