]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/io_tty_process_input: utilize auto_free
authorVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 16 Sep 2020 10:40:31 +0000 (12:40 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 2 Oct 2020 06:50:27 +0000 (08:50 +0200)
daemon/io.c

index 20833e974c1cf9e79c1a647a1b2bff5c3ae616ce..145a37e6a983f9ee36e353ec1895f26d48ea5a30 100644 (file)
@@ -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);