msgpack-rpc: Fix error handling and leak in call_request_handler

Free the arguments array after sending the response and also avoid
double-sending responses in cases of errors.
This commit is contained in:
Thiago de Arruda
2014-10-23 10:29:42 -03:00
parent d4f78127fb
commit 9abcd9a4a0

View File

@@ -455,14 +455,12 @@ static void call_request_handler(Channel *channel,
// send the response
msgpack_packer response;
msgpack_packer_init(&response, &out_buffer, msgpack_sbuffer_write);
if (error.set) {
channel_write(channel,
serialize_response(request_id, &error, NIL, &out_buffer));
}
channel_write(channel,
serialize_response(request_id, &error, result, &out_buffer));
channel_write(channel, serialize_response(request_id,
&error,
result,
&out_buffer));
// All arguments were freed already, but we still need to free the array
free(args.items);
}
static bool channel_write(Channel *channel, WBuffer *buffer)