fix: aggregate memory leaking
This commit is contained in:
parent
c94c43951e
commit
d668ee7b91
|
@ -87,6 +87,7 @@ typedef struct SUdfInterBuf {
|
||||||
} SUdfInterBuf;
|
} SUdfInterBuf;
|
||||||
typedef void *UdfcFuncHandle;
|
typedef void *UdfcFuncHandle;
|
||||||
|
|
||||||
|
//low level APIs
|
||||||
/**
|
/**
|
||||||
* setup udf
|
* setup udf
|
||||||
* @param udf, in
|
* @param udf, in
|
||||||
|
@ -115,6 +116,9 @@ int32_t doCallUdfScalarFunc(UdfcFuncHandle handle, SScalarParam *input, int32_t
|
||||||
*/
|
*/
|
||||||
int32_t doTeardownUdf(UdfcFuncHandle handle);
|
int32_t doTeardownUdf(UdfcFuncHandle handle);
|
||||||
|
|
||||||
|
void freeUdfInterBuf(SUdfInterBuf *buf);
|
||||||
|
|
||||||
|
//high level APIs
|
||||||
bool udfAggGetEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
bool udfAggGetEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||||
bool udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo);
|
bool udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo);
|
||||||
int32_t udfAggProcess(struct SqlFunctionCtx *pCtx);
|
int32_t udfAggProcess(struct SqlFunctionCtx *pCtx);
|
||||||
|
|
|
@ -836,7 +836,7 @@ int32_t udfcGetUdfTaskResultFromUvTask(SClientUdfTask *task, SClientUvTaskNode *
|
||||||
fnDebug("udfc get uv task result. task: %p, uvTask: %p", task, uvTask);
|
fnDebug("udfc get uv task result. task: %p, uvTask: %p", task, uvTask);
|
||||||
if (uvTask->type == UV_TASK_REQ_RSP) {
|
if (uvTask->type == UV_TASK_REQ_RSP) {
|
||||||
if (uvTask->rspBuf.base != NULL) {
|
if (uvTask->rspBuf.base != NULL) {
|
||||||
SUdfResponse rsp;
|
SUdfResponse rsp = {0};
|
||||||
void* buf = decodeUdfResponse(uvTask->rspBuf.base, &rsp);
|
void* buf = decodeUdfResponse(uvTask->rspBuf.base, &rsp);
|
||||||
assert(uvTask->rspBuf.len == POINTER_DISTANCE(buf, uvTask->rspBuf.base));
|
assert(uvTask->rspBuf.len == POINTER_DISTANCE(buf, uvTask->rspBuf.base));
|
||||||
task->errCode = rsp.code;
|
task->errCode = rsp.code;
|
||||||
|
@ -1569,6 +1569,7 @@ bool udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResult
|
||||||
}
|
}
|
||||||
udfRes->interResNum = buf.numOfResult;
|
udfRes->interResNum = buf.numOfResult;
|
||||||
memcpy(udfRes->interResBuf, buf.buf, buf.bufLen);
|
memcpy(udfRes->interResBuf, buf.buf, buf.bufLen);
|
||||||
|
freeUdfInterBuf(&buf);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1626,7 +1627,7 @@ int32_t udfAggProcess(struct SqlFunctionCtx *pCtx) {
|
||||||
blockDataDestroy(inputBlock);
|
blockDataDestroy(inputBlock);
|
||||||
taosArrayDestroy(tempBlock.pDataBlock);
|
taosArrayDestroy(tempBlock.pDataBlock);
|
||||||
|
|
||||||
taosMemoryFree(newState.buf);
|
freeUdfInterBuf(&newState);
|
||||||
return udfCode;
|
return udfCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1655,6 +1656,8 @@ int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock) {
|
||||||
GET_RES_INFO(pCtx)->numOfRes = udfRes->finalResNum;
|
GET_RES_INFO(pCtx)->numOfRes = udfRes->finalResNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
freeUdfInterBuf(&resultBuf);
|
||||||
|
|
||||||
int32_t numOfResults = functionFinalizeWithResultBuf(pCtx, pBlock, udfRes->finalResBuf);
|
int32_t numOfResults = functionFinalizeWithResultBuf(pCtx, pBlock, udfRes->finalResBuf);
|
||||||
releaseUdfFuncHandle(pCtx->udfName);
|
releaseUdfFuncHandle(pCtx->udfName);
|
||||||
return udfCallCode == 0 ? numOfResults : udfCallCode;
|
return udfCallCode == 0 ? numOfResults : udfCallCode;
|
||||||
|
|
|
@ -34,17 +34,7 @@ static int32_t initLog() {
|
||||||
return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, NULL, 0);
|
return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int scalarFuncTest() {
|
||||||
parseArgs(argc, argv);
|
|
||||||
initLog();
|
|
||||||
if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 0) != 0) {
|
|
||||||
fnError("failed to start since read config error");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
udfcOpen();
|
|
||||||
uv_sleep(1000);
|
|
||||||
|
|
||||||
UdfcFuncHandle handle;
|
UdfcFuncHandle handle;
|
||||||
|
|
||||||
if (doSetupUdf("udf1", &handle) != 0) {
|
if (doSetupUdf("udf1", &handle) != 0) {
|
||||||
|
@ -87,5 +77,68 @@ int main(int argc, char *argv[]) {
|
||||||
taosMemoryFree(output.columnData);
|
taosMemoryFree(output.columnData);
|
||||||
|
|
||||||
doTeardownUdf(handle);
|
doTeardownUdf(handle);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int aggregateFuncTest() {
|
||||||
|
UdfcFuncHandle handle;
|
||||||
|
|
||||||
|
if (doSetupUdf("udf2", &handle) != 0) {
|
||||||
|
fnError("setup udf failure");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSDataBlock block = {0};
|
||||||
|
SSDataBlock *pBlock = █
|
||||||
|
pBlock->pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData));
|
||||||
|
pBlock->info.numOfCols = 1;
|
||||||
|
pBlock->info.rows = 4;
|
||||||
|
char data[16] = {0};
|
||||||
|
char bitmap[4] = {0};
|
||||||
|
for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) {
|
||||||
|
SColumnInfoData colInfo = {0};
|
||||||
|
colInfo.info.type = TSDB_DATA_TYPE_INT;
|
||||||
|
colInfo.info.bytes = sizeof(int32_t);
|
||||||
|
colInfo.info.colId = 1;
|
||||||
|
colInfo.pData = data;
|
||||||
|
colInfo.nullbitmap = bitmap;
|
||||||
|
for (int32_t j = 0; j < pBlock->info.rows; ++j) {
|
||||||
|
colDataAppendInt32(&colInfo, j, &j);
|
||||||
|
}
|
||||||
|
taosArrayPush(pBlock->pDataBlock, &colInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
SUdfInterBuf buf = {0};
|
||||||
|
SUdfInterBuf newBuf = {0};
|
||||||
|
SUdfInterBuf resultBuf = {0};
|
||||||
|
doCallUdfAggInit(handle, &buf);
|
||||||
|
doCallUdfAggProcess(handle, pBlock, &buf, &newBuf);
|
||||||
|
taosArrayDestroy(pBlock->pDataBlock);
|
||||||
|
|
||||||
|
doCallUdfAggFinalize(handle, &newBuf, &resultBuf);
|
||||||
|
fprintf(stderr, "agg result: %f\n", *(double*)resultBuf.buf);
|
||||||
|
|
||||||
|
freeUdfInterBuf(&buf);
|
||||||
|
freeUdfInterBuf(&newBuf);
|
||||||
|
freeUdfInterBuf(&resultBuf);
|
||||||
|
doTeardownUdf(handle);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
parseArgs(argc, argv);
|
||||||
|
initLog();
|
||||||
|
if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 0) != 0) {
|
||||||
|
fnError("failed to start since read config error");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
udfcOpen();
|
||||||
|
uv_sleep(1000);
|
||||||
|
|
||||||
|
scalarFuncTest();
|
||||||
|
aggregateFuncTest();
|
||||||
udfcClose();
|
udfcClose();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue