Skip to content

Commit 4c29254

Browse files
committed
fixed memory leak
1 parent 24214a0 commit 4c29254

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/execution/command_parser.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ int ParseScriptRunCommand(RedisAI_RunInfo *rinfo, RAI_DagOp *currentOp, RedisMod
356356
int res = REDISMODULE_ERR;
357357
// Build a ScriptRunCtx from command.
358358
RedisModuleCtx *ctx = RedisModule_GetThreadSafeContext(NULL);
359-
359+
RAI_ScriptRunCtx *sctx = NULL;
360360
RAI_Script *script = _ScriptCommand_GetScript(ctx, argv[1], rinfo->err);
361361
if (!script) {
362362
goto cleanup;
@@ -370,7 +370,7 @@ int ParseScriptRunCommand(RedisAI_RunInfo *rinfo, RAI_DagOp *currentOp, RedisMod
370370
goto cleanup;
371371
}
372372

373-
RAI_ScriptRunCtx *sctx = RAI_ScriptRunCtxCreate(script, func_name);
373+
sctx = RAI_ScriptRunCtxCreate(script, func_name);
374374
long long timeout = 0;
375375
if (_ScriptRunCommand_ParseArgs(ctx, argv, argc, rinfo->err, &currentOp->inkeys,
376376
&currentOp->outkeys, &timeout,
@@ -381,9 +381,6 @@ int ParseScriptRunCommand(RedisAI_RunInfo *rinfo, RAI_DagOp *currentOp, RedisMod
381381
RAI_SetError(rinfo->err, RAI_EDAGBUILDER, "ERR TIMEOUT not allowed within a DAG command");
382382
goto cleanup;
383383
}
384-
currentOp->sctx = sctx;
385-
currentOp->commandType = REDISAI_DAG_CMD_SCRIPTRUN;
386-
currentOp->devicestr = sctx->script->devicestr;
387384

388385
if (rinfo->single_op_dag) {
389386
rinfo->timeout = timeout;
@@ -392,10 +389,18 @@ int ParseScriptRunCommand(RedisAI_RunInfo *rinfo, RAI_DagOp *currentOp, RedisMod
392389
REDISMODULE_ERR)
393390
goto cleanup;
394391
}
392+
currentOp->sctx = sctx;
393+
currentOp->commandType = REDISAI_DAG_CMD_SCRIPTRUN;
394+
currentOp->devicestr = sctx->script->devicestr;
395395
res = REDISMODULE_OK;
396+
RedisModule_FreeThreadSafeContext(ctx);
397+
return res;
396398

397399
cleanup:
398400
RedisModule_FreeThreadSafeContext(ctx);
401+
if(sctx) {
402+
RAI_ScriptRunCtxFree(sctx);
403+
}
399404
return res;
400405
}
401406

0 commit comments

Comments
 (0)