Merge pull request #13202 from taosdata/fix/idxMemLeak

fix: avoid mem leak
This commit is contained in:
Yihao Deng 2022-05-30 09:22:03 +08:00 committed by GitHub
commit 1d794208fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View File

@ -1324,7 +1324,7 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb
if (FST_NODE_ADDR(p->node) != fstGetRootAddr(sws->fst)) { if (FST_NODE_ADDR(p->node) != fstGetRootAddr(sws->fst)) {
taosArrayPop(sws->inp); taosArrayPop(sws->inp);
} }
// streamStateDestroy(p); streamStateDestroy(p);
continue; continue;
} }
FstTransition trn; FstTransition trn;

View File

@ -93,14 +93,15 @@ FstSlice fstSliceCreate(uint8_t* data, uint64_t len) {
// just shallow copy // just shallow copy
FstSlice fstSliceCopy(FstSlice* s, int32_t start, int32_t end) { FstSlice fstSliceCopy(FstSlice* s, int32_t start, int32_t end) {
FstString* str = s->str; FstString* str = s->str;
str->ref++; atomic_add_fetch_32(&str->ref, 1);
FstSlice t = {.str = str, .start = start + s->start, .end = end + s->start}; FstSlice t = {.str = str, .start = start + s->start, .end = end + s->start};
return t; return t;
} }
FstSlice fstSliceDeepCopy(FstSlice* s, int32_t start, int32_t end) { FstSlice fstSliceDeepCopy(FstSlice* s, int32_t start, int32_t end) {
int32_t tlen = end - start + 1; int32_t tlen = end - start + 1;
int32_t slen; int32_t slen;
uint8_t* data = fstSliceData(s, &slen); uint8_t* data = fstSliceData(s, &slen);
assert(tlen <= slen); assert(tlen <= slen);
@ -129,8 +130,9 @@ uint8_t* fstSliceData(FstSlice* s, int32_t* size) {
} }
void fstSliceDestroy(FstSlice* s) { void fstSliceDestroy(FstSlice* s) {
FstString* str = s->str; FstString* str = s->str;
str->ref--;
if (str->ref == 0) { int32_t ref = atomic_sub_fetch_32(&str->ref, 1);
if (ref == 0) {
taosMemoryFree(str->data); taosMemoryFree(str->data);
taosMemoryFree(str); taosMemoryFree(str);
s->str = NULL; s->str = NULL;