From 739568fcb8c3f583e217e69bcd70fa7aa80dd2ae Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 7 Mar 2016 21:12:03 +0000 Subject: [PATCH] runtime: fix sloppy memory management in cache_put. --- artiq/runtime/session.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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;