From: Vladimír Čunát Date: Wed, 16 Sep 2020 10:40:31 +0000 (+0200) Subject: daemon/io_tty_process_input: utilize auto_free X-Git-Tag: v5.2.0~28^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d1b534ebd28d45afa5e26936de7545245f4fc79d;p=thirdparty%2Fknot-resolver.git daemon/io_tty_process_input: utilize auto_free --- diff --git a/daemon/io.c b/daemon/io.c index 20833e974..145a37e6a 100644 --- a/daemon/io.c +++ b/daemon/io.c @@ -13,6 +13,7 @@ #include "daemon/worker.h" #include "daemon/tls.h" #include "daemon/session.h" +#include "contrib/cleanup.h" #include "lib/utils.h" #define negotiate_bufsize(func, handle, bufsize_want) do { \ @@ -458,7 +459,7 @@ struct io_stream_data { */ void io_tty_process_input(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { - char *commands = buf ? buf->base : NULL; /* To be free()d on return. */ + auto_free char *commands = buf ? buf->base : NULL; /* Set output streams */ FILE *out = stdout; @@ -468,11 +469,9 @@ void io_tty_process_input(uv_stream_t *stream, ssize_t nread, const uv_buf_t *bu if (nread < 0 || uv_fileno((uv_handle_t *)stream, &stream_fd)) { mp_delete(data->pool->ctx); uv_close((uv_handle_t *)stream, (uv_close_cb) free); - free(commands); return; } if (nread <= 0) { - free(commands); return; } if (stream_fd != STDIN_FILENO) { @@ -611,7 +610,6 @@ void io_tty_process_input(uv_stream_t *stream, ssize_t nread, const uv_buf_t *bu } finish: - free(commands); /* Close if redirected */ if (stream_fd != STDIN_FILENO) { fclose(out);