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; }