Skip to content

Commit 5c7813e

Browse files
authored
Safely add to arrays + fix for #443 (#449)
* Make sure we reassign the pointer in array_append * Fix case-sensitive comparison for devicestr * Fix sanitizer tests
1 parent 5e43287 commit 5c7813e

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

src/backends/tensorflow.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,12 @@ RAI_Model *RAI_ModelCreateTF(RAI_Backend backend, const char* devicestr, RAI_Mod
392392

393393
char **inputs_ = array_new(char*, ninputs);
394394
for (long long i=0; i<ninputs; i++) {
395-
array_append(inputs_, RedisModule_Strdup(inputs[i]));
395+
inputs_ = array_append(inputs_, RedisModule_Strdup(inputs[i]));
396396
}
397397

398398
char **outputs_ = array_new(char*, noutputs);
399399
for (long long i=0; i<noutputs; i++) {
400-
array_append(outputs_, RedisModule_Strdup(outputs[i]));
400+
outputs_ = array_append(outputs_, RedisModule_Strdup(outputs[i]));
401401
}
402402

403403
char* buffer = RedisModule_Calloc(modellen, sizeof(*buffer));

src/background_workers.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ void *RedisAI_Run_ThreadMain(void *arg) {
143143

144144
// We add the current item to the list of evicted items. If it's the
145145
// first time around this will be the queue front.
146-
array_append(evicted_items, item);
147-
array_append(batch_rinfo, rinfo);
146+
evicted_items = array_append(evicted_items, item);
147+
batch_rinfo = array_append(batch_rinfo, rinfo);
148148

149149
// If the item is a scriptrun, we stop looking for matching items to
150150
// batch because there's no batching for script
@@ -208,8 +208,8 @@ void *RedisAI_Run_ThreadMain(void *arg) {
208208

209209
// If all previous checks pass, then keep track of the item
210210
// in the list of evicted items
211-
array_append(evicted_items, next_item);
212-
array_append(batch_rinfo, next_rinfo);
211+
evicted_items = array_append(evicted_items, next_item);
212+
batch_rinfo = array_append(batch_rinfo, next_rinfo);
213213

214214
// Update the batchsize and go to the next item to see if
215215
// there's anything else to batch

src/dag.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void RedisAI_DagRunSession_TensorGet_Step(RedisAI_RunInfo *rinfo, RAI_DagOp *cur
8686
RAI_Tensor *outTensor = NULL;
8787
// TODO: check tensor copy return value
8888
RAI_TensorDeepCopy(t, &outTensor);
89-
array_append(currentOp->outTensors, outTensor);
89+
currentOp->outTensors = array_append(currentOp->outTensors, outTensor);
9090
}
9191
}
9292

@@ -624,7 +624,7 @@ int RedisAI_DagRunSyntaxParser(RedisModuleCtx *ctx, RedisModuleString **argv,
624624
rinfo->use_local_context = 1;
625625
RAI_DagOp *currentDagOp = NULL;
626626
RAI_InitDagOp(&currentDagOp);
627-
array_append(rinfo->dagOps, currentDagOp);
627+
rinfo->dagOps = array_append(rinfo->dagOps, currentDagOp);
628628

629629
int persistFlag = 0;
630630
int loadFlag = 0;
@@ -666,7 +666,7 @@ int RedisAI_DagRunSyntaxParser(RedisModuleCtx *ctx, RedisModuleString **argv,
666666
rinfo->dagNumberCommands++;
667667
RAI_DagOp *currentDagOp = NULL;
668668
RAI_InitDagOp(&currentDagOp);
669-
array_append(rinfo->dagOps, currentDagOp);
669+
rinfo->dagOps = array_append(rinfo->dagOps, currentDagOp);
670670
}
671671
chainingOpCount++;
672672
} else {
@@ -878,7 +878,7 @@ int RedisAI_DagRunSyntaxParser(RedisModuleCtx *ctx, RedisModuleString **argv,
878878
const char* devicestr = rinfo->dagOps[i]->devicestr;
879879
bool found = false;
880880
for (long long j=0; j<array_len(devices); j++) {
881-
if (strcmp(devicestr, devices[j]) == 0) {
881+
if (strcasecmp(devicestr, devices[j]) == 0) {
882882
found = true;
883883
break;
884884
}

src/model.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ static void RAI_Model_AofRewrite(RedisModuleIO *aof, RedisModuleString *key, voi
193193
RedisModuleCtx *ctx = RedisModule_GetContextFromIO(aof);
194194

195195
for (size_t i=0; i<model->ninputs; i++) {
196-
array_append(inputs_, RedisModule_CreateString(ctx, model->inputs[i], strlen(model->inputs[i])));
196+
inputs_ = array_append(inputs_, RedisModule_CreateString(ctx, model->inputs[i], strlen(model->inputs[i])));
197197
}
198198

199199
for (size_t i=0; i<model->noutputs; i++) {
200-
array_append(outputs_, RedisModule_CreateString(ctx, model->outputs[i], strlen(model->outputs[i])));
200+
outputs_ = array_append(outputs_, RedisModule_CreateString(ctx, model->outputs[i], strlen(model->outputs[i])));
201201
}
202202

203203
long long chunk_size = getModelChunkSize();
@@ -206,7 +206,7 @@ static void RAI_Model_AofRewrite(RedisModuleIO *aof, RedisModuleString *key, voi
206206

207207
for (size_t i=0; i<n_chunks; i++) {
208208
size_t chunk_len = i < n_chunks - 1 ? chunk_size : len % chunk_size;
209-
array_append(buffers_, RedisModule_CreateString(ctx, buffer + i * chunk_size, chunk_len));
209+
buffers_ = array_append(buffers_, RedisModule_CreateString(ctx, buffer + i * chunk_size, chunk_len));
210210
}
211211

212212
if (buffer) {

src/tensor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ int RAI_parseTensorSetArgs(RedisModuleCtx *ctx, RedisModuleString **argv, int ar
825825
return -1;
826826
}
827827
ndims++;
828-
array_append(dims, dimension);
828+
dims = array_append(dims, dimension);
829829
len *= dimension;
830830
}
831831
}

test/tests_sanitizer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test_sanitizer_dagrun_mobilenet_v1(env):
1212
if (not TEST_TF or not TEST_PT):
1313
return
1414
con = env.getConnection()
15-
mem_allocator = con.execute_command('info', 'memory')['mem_allocator']
15+
mem_allocator = con.info()['mem_allocator']
1616
if 'jemalloc' in mem_allocator:
1717
print("exiting sanitizer test given we're not using stdlib allocator")
1818
return
@@ -48,7 +48,7 @@ def test_sanitizer_modelrun_mobilenet_v1(env):
4848
if (not TEST_TF or not TEST_PT):
4949
return
5050
con = env.getConnection()
51-
mem_allocator = con.execute_command('info', 'memory')['mem_allocator']
51+
mem_allocator = con.info()['mem_allocator']
5252
if 'jemalloc' in mem_allocator:
5353
print("exiting sanitizer test given we're not using stdlib allocator")
5454
return

0 commit comments

Comments
 (0)