From f5fd0c950ce1bf19fd5186fd2b1f2cc67f5de3ec Mon Sep 17 00:00:00 2001 From: "Gao,Yan" Date: Tue, 6 Oct 2015 17:48:05 +0200 Subject: [PATCH] Fix: ipc: Prevent fd and memory leaks in handle_new_connection() In handle_new_connection(), connection_accept() could fail, which would leave the state of the connection inactive. Previously, in this case, the socket and the allocated qb_ipcs_connection would be leaked. --- lib/ipc_setup.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/ipc_setup.c b/lib/ipc_setup.c index 28a0ddc02..06257c1ce 100644 --- a/lib/ipc_setup.c +++ b/lib/ipc_setup.c @@ -556,7 +556,14 @@ handle_new_connection(struct qb_ipcs_service *s, "Error in connection setup (%s)", c->description); } - qb_ipcs_disconnect(c); + + if (c->state == QB_IPCS_CONNECTION_INACTIVE) { + /* This removes the initial alloc ref */ + qb_ipcs_connection_unref(c); + qb_ipcc_us_sock_close(sock); + } else { + qb_ipcs_disconnect(c); + } } return res; }