From a19a5953433c86811df80c59de7ec6346c62be32 Mon Sep 17 00:00:00 2001 From: Petr Rockai Date: Mon, 8 Oct 2012 18:35:30 +0200 Subject: [PATCH] libdaemon-client: Fix a memory leak in daemon_send. --- libdaemon/client/daemon-client.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libdaemon/client/daemon-client.c b/libdaemon/client/daemon-client.c index e34a2a00f..c87856c0a 100644 --- a/libdaemon/client/daemon-client.c +++ b/libdaemon/client/daemon-client.c @@ -73,12 +73,13 @@ daemon_reply daemon_send(daemon_handle h, daemon_request rq) { daemon_reply reply = { .cft = NULL, .error = 0 }; assert(h.socket_fd >= 0); + char *buffer = rq.buffer; - if (!rq.buffer) - dm_config_write_node(rq.cft->root, buffer_line, &rq.buffer); + if (!buffer) + dm_config_write_node(rq.cft->root, buffer_line, &buffer); - assert(rq.buffer); - if (!write_buffer(h.socket_fd, rq.buffer, strlen(rq.buffer))) + assert(buffer); + if (!write_buffer(h.socket_fd, buffer, strlen(buffer))) reply.error = errno; if (read_buffer(h.socket_fd, &reply.buffer)) { @@ -88,6 +89,9 @@ daemon_reply daemon_send(daemon_handle h, daemon_request rq) } else reply.error = errno; + if (buffer != rq.buffer) + dm_free(buffer); + return reply; }