From 7b8dbc8d8fd2d74bbc1afd6d6ec657c1ed8ad0a5 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 12 Jan 2010 10:51:30 -0800 Subject: [PATCH] jsonrpc: Fix memory leak in jsonrpc_session_send() when not connected. Partial fix for bug #2373. --- lib/jsonrpc.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c index f648f6b1..562a2870 100644 --- a/lib/jsonrpc.c +++ b/lib/jsonrpc.c @@ -172,6 +172,7 @@ jsonrpc_log_msg(const struct jsonrpc *rpc, const char *title, } } +/* Always takes ownership of 'msg', regardless of success. */ int jsonrpc_send(struct jsonrpc *rpc, struct jsonrpc_msg *msg) { @@ -268,6 +269,7 @@ jsonrpc_recv_wait(struct jsonrpc *rpc) } } +/* Always takes ownership of 'msg', regardless of success. */ int jsonrpc_send_block(struct jsonrpc *rpc, struct jsonrpc_msg *msg) { @@ -304,6 +306,7 @@ jsonrpc_recv_block(struct jsonrpc *rpc, struct jsonrpc_msg **msgp) } } +/* Always takes ownership of 'request', regardless of success. */ int jsonrpc_transact_block(struct jsonrpc *rpc, struct jsonrpc_msg *request, struct jsonrpc_msg **replyp) @@ -792,10 +795,16 @@ jsonrpc_session_get_name(const struct jsonrpc_session *s) return reconnect_get_name(s->reconnect); } +/* Always takes ownership of 'msg', regardless of success. */ int jsonrpc_session_send(struct jsonrpc_session *s, struct jsonrpc_msg *msg) { - return s->rpc ? jsonrpc_send(s->rpc, msg) : ENOTCONN; + if (s->rpc) { + return jsonrpc_send(s->rpc, msg); + } else { + jsonrpc_msg_destroy(msg); + return ENOTCONN; + } } struct jsonrpc_msg * -- 2.30.2