Fix leak / lack of reply on invalid util requests 63/240363/1
authorMichal Bloch <m.bloch@samsung.com>
Wed, 5 Aug 2020 14:43:30 +0000 (16:43 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Wed, 5 Aug 2020 15:04:56 +0000 (17:04 +0200)
Change-Id: Ie3dc944f73bed2bbbf1636899fecc071e626195e
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/logger/logger.c

index c3b53b0..1e9c156 100644 (file)
@@ -1506,10 +1506,12 @@ static int service_writer_handle_req_util(struct logger* server, struct writer*
        if (msg->data[msg->length - sizeof(struct dlog_control_msg)] != 0)
                return -EINVAL;
 
+       __attribute__((cleanup(reader_pipe_cleanup))) struct reader_pipe *reader = NULL;
+
        struct dlogutil_line_params params;
        int retval = get_dlogutil_line_params(msg->data, &params);
        if (retval < 0)
-               return retval;
+               goto cleanup;
 
        if (params.file_path) {
                /* Do not trust writer-based readers (only config-based).
@@ -1521,10 +1523,10 @@ static int service_writer_handle_req_util(struct logger* server, struct writer*
                 * middleman and become able to write to a file directly
                 * though. The daemon should become able to receive an
                 * opened file descriptor from a writer. */
-               return -EPERM;
+               retval = -EPERM;
+               goto cleanup;
        }
 
-       __attribute__((cleanup(reader_pipe_cleanup))) struct reader_pipe *reader = NULL;
        retval = reader_pipe_init_with_writer(&reader, wr, server, params.filter, params.file, params.monitor, params.is_dumping);
        if (retval != 0)
                goto cleanup;