Skip to content

Commit c23cd25

Browse files
committed
Fix leaks in model_RDB_load, and in StatsRunInfo (key was not freed).
1 parent 1cf97a9 commit c23cd25

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

src/DAG/dag_parser.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ int DAG_CommandParser(RedisModuleCtx *ctx, RedisModuleString **argv, int argc, b
229229
return REDISMODULE_ERR;
230230
}
231231
currentOp->devicestr = mto->devicestr;
232+
RAI_HoldString(NULL, argv[arg_pos + 1]);
232233
currentOp->runkey = argv[arg_pos + 1];
233234
currentOp->mctx = RAI_ModelRunCtxCreate(mto);
234235
}
@@ -249,6 +250,7 @@ int DAG_CommandParser(RedisModuleCtx *ctx, RedisModuleString **argv, int argc, b
249250
}
250251
currentOp->devicestr = sto->devicestr;
251252
const char *functionName = RedisModule_StringPtrLen(argv[arg_pos + 2], NULL);
253+
RAI_HoldString(NULL, argv[arg_pos + 1]);
252254
currentOp->runkey = argv[arg_pos + 1];
253255
currentOp->sctx = RAI_ScriptRunCtxCreate(sto, functionName);
254256
}

src/backends/tensorflow.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ RAI_Model *RAI_ModelCreateTF(RAI_Backend backend, const char *devicestr, RAI_Mod
250250
char *msg = RedisModule_Calloc(60 + len, sizeof(*msg));
251251
sprintf(msg, "ERR Input node named \"%s\" not found in TF graph.", inputs[i]);
252252
RAI_SetError(error, RAI_EMODELIMPORT, msg);
253+
RedisModule_Free(msg);
253254
return NULL;
254255
}
255256
}

src/model.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,24 @@ static void *RAI_Model_RdbLoad(struct RedisModuleIO *io, int encver) {
107107
return NULL;
108108
}
109109

110+
for (size_t i = 0; i < ninputs; i++) {
111+
RedisModule_Free(inputs[i]);
112+
}
113+
for (size_t i = 0; i < noutputs; i++) {
114+
RedisModule_Free(outputs[i]);
115+
}
110116
RedisModule_Free(inputs);
111117
RedisModule_Free(outputs);
112118
RedisModule_Free(buffer);
113119

114120
RedisModuleCtx *stats_ctx = RedisModule_GetContextFromIO(io);
115121
RedisModuleString *stats_keystr =
116122
RedisModule_CreateStringFromString(stats_ctx, RedisModule_GetKeyNameFromIO(io));
117-
const char *stats_devicestr = RedisModule_Strdup(devicestr);
118-
RedisModuleString *stats_tag = RAI_HoldString(NULL, tag);
119123

120-
model->infokey =
121-
RAI_AddStatsEntry(stats_ctx, stats_keystr, RAI_MODEL, backend, stats_devicestr, stats_tag);
124+
model->infokey = RAI_AddStatsEntry(stats_ctx, stats_keystr, RAI_MODEL, backend, devicestr, tag);
122125

126+
RedisModule_FreeString(NULL, tag);
127+
RedisModule_Free(devicestr);
123128
RedisModule_FreeString(NULL, stats_keystr);
124129

125130
return model;
@@ -371,7 +376,6 @@ void RAI_ModelFree(RAI_Model *model, RAI_Error *err) {
371376
}
372377

373378
RedisModule_FreeString(NULL, model->tag);
374-
375379
RAI_RemoveStatsEntry(model->infokey);
376380

377381
RedisModule_Free(model);

src/run_info.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ void RAI_FreeDagOp(RAI_DagOp *dagOp) {
113113
}
114114
array_free(dagOp->argv);
115115
}
116+
if (dagOp->runkey)
117+
RedisModule_FreeString(NULL, dagOp->runkey);
116118
// dagOp->inkeys is released on all argv release above
117119
// dagOp->outkeys is released on all argv release above
118120
// dagOp->outTensors is released on RunInfo after checking what tensors to

src/stats.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ void RAI_FreeRunStats(struct RedisAI_RunStats *rstats) {
109109
if (rstats->tag) {
110110
RedisModule_FreeString(NULL, rstats->tag);
111111
}
112+
if (rstats->key) {
113+
RedisModule_FreeString(NULL, rstats->key);
114+
}
112115
RedisModule_Free(rstats);
113116
}
114117
}

0 commit comments

Comments
 (0)