@@ -356,7 +356,7 @@ int ParseScriptRunCommand(RedisAI_RunInfo *rinfo, RAI_DagOp *currentOp, RedisMod
356
356
int res = REDISMODULE_ERR ;
357
357
// Build a ScriptRunCtx from command.
358
358
RedisModuleCtx * ctx = RedisModule_GetThreadSafeContext (NULL );
359
-
359
+ RAI_ScriptRunCtx * sctx = NULL ;
360
360
RAI_Script * script = _ScriptCommand_GetScript (ctx , argv [1 ], rinfo -> err );
361
361
if (!script ) {
362
362
goto cleanup ;
@@ -370,7 +370,7 @@ int ParseScriptRunCommand(RedisAI_RunInfo *rinfo, RAI_DagOp *currentOp, RedisMod
370
370
goto cleanup ;
371
371
}
372
372
373
- RAI_ScriptRunCtx * sctx = RAI_ScriptRunCtxCreate (script , func_name );
373
+ sctx = RAI_ScriptRunCtxCreate (script , func_name );
374
374
long long timeout = 0 ;
375
375
if (_ScriptRunCommand_ParseArgs (ctx , argv , argc , rinfo -> err , & currentOp -> inkeys ,
376
376
& currentOp -> outkeys , & timeout ,
@@ -381,9 +381,6 @@ int ParseScriptRunCommand(RedisAI_RunInfo *rinfo, RAI_DagOp *currentOp, RedisMod
381
381
RAI_SetError (rinfo -> err , RAI_EDAGBUILDER , "ERR TIMEOUT not allowed within a DAG command" );
382
382
goto cleanup ;
383
383
}
384
- currentOp -> sctx = sctx ;
385
- currentOp -> commandType = REDISAI_DAG_CMD_SCRIPTRUN ;
386
- currentOp -> devicestr = sctx -> script -> devicestr ;
387
384
388
385
if (rinfo -> single_op_dag ) {
389
386
rinfo -> timeout = timeout ;
@@ -392,10 +389,18 @@ int ParseScriptRunCommand(RedisAI_RunInfo *rinfo, RAI_DagOp *currentOp, RedisMod
392
389
REDISMODULE_ERR )
393
390
goto cleanup ;
394
391
}
392
+ currentOp -> sctx = sctx ;
393
+ currentOp -> commandType = REDISAI_DAG_CMD_SCRIPTRUN ;
394
+ currentOp -> devicestr = sctx -> script -> devicestr ;
395
395
res = REDISMODULE_OK ;
396
+ RedisModule_FreeThreadSafeContext (ctx );
397
+ return res ;
396
398
397
399
cleanup :
398
400
RedisModule_FreeThreadSafeContext (ctx );
401
+ if (sctx ) {
402
+ RAI_ScriptRunCtxFree (sctx );
403
+ }
399
404
return res ;
400
405
}
401
406
0 commit comments