Fix: uninitialized directory handle finalized on error path
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 9 Sep 2019 15:14:47 +0000 (11:14 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 19 Sep 2019 19:31:48 +0000 (15:31 -0400)
relay_create_trace_chunk() creates a session output directory handle
and assigns it to a trace chunk. Since a handle doesn't have a
dedicated "uninitialized" state, reduce its lifetime and don't
generically finalize it in error paths.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-relayd/main.c

index 431a0d67a056a227c6b58afac9da052a779ac46d..8e67f7664f6a44828cae6c2dd078b4c5d06b3ad9 100644 (file)
@@ -2386,13 +2386,6 @@ static int relay_create_trace_chunk(const struct lttcomm_relayd_hdr *recv_hdr,
                }
        }
 
-       ret = session_init_output_directory_handle(
-                       conn->session, &session_output);
-       if (ret) {
-               reply_code = LTTNG_ERR_CREATE_DIR_FAIL;
-               goto end;
-       }
-
        chunk_status = lttng_trace_chunk_set_credentials_current_user(chunk);
        if (chunk_status != LTTNG_TRACE_CHUNK_STATUS_OK) {
                reply_code = LTTNG_ERR_UNK;
@@ -2400,7 +2393,14 @@ static int relay_create_trace_chunk(const struct lttcomm_relayd_hdr *recv_hdr,
                goto end;
        }
 
+       ret = session_init_output_directory_handle(
+                       conn->session, &session_output);
+       if (ret) {
+               reply_code = LTTNG_ERR_CREATE_DIR_FAIL;
+               goto end;
+       }
        chunk_status = lttng_trace_chunk_set_as_owner(chunk, &session_output);
+       lttng_directory_handle_fini(&session_output);
        if (chunk_status != LTTNG_TRACE_CHUNK_STATUS_OK) {
                reply_code = LTTNG_ERR_UNK;
                ret = -1;
@@ -2456,7 +2456,6 @@ end:
 end_no_reply:
        lttng_trace_chunk_put(chunk);
        lttng_trace_chunk_put(published_chunk);
-       lttng_directory_handle_fini(&session_output);
        return ret;
 }
 
This page took 0.02719 seconds and 4 git commands to generate.