diff --git a/artiq/runtime/session.c b/artiq/runtime/session.c index 5c4333480..fb6e4dcaf 100644 --- a/artiq/runtime/session.c +++ b/artiq/runtime/session.c @@ -1027,7 +1027,6 @@ static int process_kmsg(struct msg_base *umsg) struct cache_row *row = NULL; for(struct cache_row *iter = cache; iter; iter = iter->next) { if(!strcmp(iter->key, request->key)) { - free(iter->elements); row = iter; break; } @@ -1042,11 +1041,14 @@ static int process_kmsg(struct msg_base *umsg) } if(!row->borrowed) { - if(request->length != 0) { - row->length = request->length; + row->length = request->length; + if(row->length != 0) { row->elements = calloc(row->length, sizeof(int32_t)); memcpy(row->elements, request->elements, sizeof(int32_t) * row->length); + } else { + free(row->elements); + row->elements = NULL; } reply.succeeded = 1;