Skip to content

Commit 112649b

Browse files
committed
Fix valgrind (in dag parsing error)
1 parent d4d4277 commit 112649b

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

src/execution/parsing/dag_parser.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ int ParseDAGExecuteOps(RedisAI_RunInfo *rinfo, RAI_DagOp **ops, bool ro) {
172172
currentOp->inkeys = array_append(currentOp->inkeys, currentOp->argv[1]);
173173
currentOp->fmt = ParseTensorGetArgs(rinfo->err, currentOp->argv, currentOp->argc);
174174
if (currentOp->fmt == TENSOR_NONE) {
175-
goto cleanup;
175+
return REDISMODULE_ERR;
176176
}
177177
continue;
178178
}
@@ -183,14 +183,14 @@ int ParseDAGExecuteOps(RedisAI_RunInfo *rinfo, RAI_DagOp **ops, bool ro) {
183183
currentOp->outkeys = array_append(currentOp->outkeys, currentOp->argv[1]);
184184
if (RAI_parseTensorSetArgs(currentOp->argv, currentOp->argc, &currentOp->outTensor, 0,
185185
rinfo->err) == -1) {
186-
goto cleanup;
186+
return REDISMODULE_ERR;
187187
}
188188
continue;
189189
}
190190
if (!strcasecmp(arg_string, "AI.MODELEXECUTE")) {
191191
if (ParseModelExecuteCommand(rinfo, currentOp, currentOp->argv, currentOp->argc) !=
192192
REDISMODULE_OK) {
193-
goto cleanup;
193+
return REDISMODULE_ERR;
194194
}
195195
continue;
196196
}
@@ -199,29 +199,29 @@ int ParseDAGExecuteOps(RedisAI_RunInfo *rinfo, RAI_DagOp **ops, bool ro) {
199199
// Scripts can contain call to Redis commands (that may write to Redis)
200200
RAI_SetError(rinfo->err, RAI_EDAGBUILDER,
201201
"ERR AI.SCRIPTEXECUTE command cannot be specified in a read-only DAG");
202-
goto cleanup;
202+
return REDISMODULE_ERR;
203203
}
204204
if (ParseScriptExecuteCommand(rinfo, currentOp, currentOp->argv, currentOp->argc) !=
205205
REDISMODULE_OK) {
206-
goto cleanup;
206+
return REDISMODULE_ERR;
207207
}
208208
continue;
209209
}
210210
if (!strcasecmp(arg_string, "AI.MODELRUN")) {
211211
RAI_SetError(rinfo->err, RAI_EDAGBUILDER,
212212
"Deprecated AI.MODELRUN"
213213
" cannot be used in AI.DAGEXECUTE command");
214-
goto cleanup;
214+
return REDISMODULE_ERR;
215215
}
216216
if (!strcasecmp(arg_string, "AI.SCRIPTRUN")) {
217217
RAI_SetError(rinfo->err, RAI_EDAGBUILDER,
218218
"Deprecated AI.SCRIPTRUN"
219219
" cannot be used in AI.DAGEXECUTE command");
220-
goto cleanup;
220+
return REDISMODULE_ERR;
221221
}
222222
// If none of the cases match, we have an invalid op.
223223
RAI_SetError(rinfo->err, RAI_EDAGBUILDER, "Unsupported command within DAG");
224-
goto cleanup;
224+
return REDISMODULE_ERR;
225225
}
226226

227227
// After validating all the ops, insert them to the DAG.
@@ -230,12 +230,6 @@ int ParseDAGExecuteOps(RedisAI_RunInfo *rinfo, RAI_DagOp **ops, bool ro) {
230230
}
231231
rinfo->dagOpCount = array_len(rinfo->dagOps);
232232
return REDISMODULE_OK;
233-
234-
cleanup:
235-
for (size_t i = 0; i < array_len(ops); i++) {
236-
RAI_FreeDagOp(ops[i]);
237-
}
238-
return REDISMODULE_ERR;
239233
}
240234

241235
int DAGInitialParsing(RedisAI_RunInfo *rinfo, RedisModuleCtx *ctx, RedisModuleString **argv,
@@ -335,7 +329,6 @@ int DAGInitialParsing(RedisAI_RunInfo *rinfo, RedisModuleCtx *ctx, RedisModuleSt
335329
int ParseDAGExecuteCommand(RedisAI_RunInfo *rinfo, RedisModuleCtx *ctx, RedisModuleString **argv,
336330
int argc, bool dag_ro) {
337331

338-
int res = REDISMODULE_ERR;
339332
// The minimal command is of the form: AI.DAGEXECUTE(_RO) KEYS/LOAD/PERSIST 1 <key> |>
340333
// AI.TENSORGET <key>
341334
if (argc < 7) {
@@ -346,7 +339,7 @@ int ParseDAGExecuteCommand(RedisAI_RunInfo *rinfo, RedisModuleCtx *ctx, RedisMod
346339
RAI_SetError(rinfo->err, RAI_EDAGBUILDER,
347340
"ERR missing arguments for 'AI.DAGEXECUTE' command");
348341
}
349-
return res;
342+
return REDISMODULE_ERR;
350343
}
351344

352345
// First we parse KEYS, LOAD, PERSIST and TIMEOUT parts, and we collect the DAG ops' args.
@@ -368,9 +361,13 @@ int ParseDAGExecuteCommand(RedisAI_RunInfo *rinfo, RedisModuleCtx *ctx, RedisMod
368361
}
369362
AI_dictRelease(rinfo->tensorsNamesToIndices);
370363
rinfo->tensorsNamesToIndices = NULL;
371-
res = REDISMODULE_OK;
364+
array_free(dag_ops);
365+
return REDISMODULE_OK;
372366

373367
cleanup:
368+
for (size_t i = 0; i < array_len(dag_ops); i++) {
369+
RAI_FreeDagOp(dag_ops[i]);
370+
}
374371
array_free(dag_ops);
375-
return res;
372+
return REDISMODULE_ERR;
376373
}

src/execution/parsing/deprecated.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ int ParseDAGRunCommand(RedisAI_RunInfo *rinfo, RedisModuleCtx *ctx, RedisModuleS
586586
// First we parse LOAD, PERSIST and TIMEOUT parts, and we collect the DAG ops' args.
587587
array_new_on_stack(RAI_DagOp *, 10, dag_ops);
588588
if (DAGInitialParsing(rinfo, ctx, argv, argc, dag_ro, &dag_ops) != REDISMODULE_OK) {
589-
return REDISMODULE_ERR;
589+
goto cleanup;
590590
}
591591

592592
if (ParseDAGRunOps(rinfo, dag_ops) != REDISMODULE_OK) {

0 commit comments

Comments
 (0)