From 9abcd9a4a095ea1c96efb3a63890e8b919b20d22 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Thu, 23 Oct 2014 10:29:42 -0300 Subject: 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. --- src/nvim/msgpack_rpc/channel.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c index 3622c8252d..7b51eefa3a 100644 --- a/src/nvim/msgpack_rpc/channel.c +++ b/src/nvim/msgpack_rpc/channel.c @@ -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) -- cgit