From 90d1062a55627dfe71a326d67a75efad225e1da1 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 24 Aug 2018 14:50:06 +0930 Subject: [PATCH] daemon_conn: fix memory leak when passing an fd. Signed-off-by: Rusty Russell --- common/daemon_conn.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common/daemon_conn.c b/common/daemon_conn.c index d41d4952d..1a677b41f 100644 --- a/common/daemon_conn.c +++ b/common/daemon_conn.c @@ -22,9 +22,11 @@ again: msg = msg_dequeue(&dc->out); if (msg) { int fd = msg_extract_fd(msg); - if (fd >= 0) + if (fd >= 0) { + tal_free(msg); return io_send_fd(conn, fd, true, daemon_conn_write_next, dc); + } return io_write_wire(conn, take(msg), daemon_conn_write_next, dc); } else if (dc->msg_queue_cleared_cb) { @@ -52,6 +54,7 @@ bool daemon_conn_sync_flush(struct daemon_conn *dc) while ((msg = msg_dequeue(&dc->out)) != NULL) { int fd = msg_extract_fd(msg); if (fd >= 0) { + tal_free(msg); if (!fdpass_send(daemon_fd, fd)) break; } else if (!wire_sync_write(daemon_fd, take(msg)))