runtime: fix sloppy memory management in cache_put.

This commit is contained in:
whitequark 2016-03-07 21:12:03 +00:00
parent 9ffa8cbb11
commit 739568fcb8

View File

@ -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;