From 837c04d660e47a94675582209c6cb2fe71ebad0c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 2 Nov 2021 22:31:15 -0400 Subject: [PATCH] Fix: sessiond: snapshot: leak of trace chunk MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Valgrind reports a leak after every snapshot record command: ==827791== 430 (280 direct, 150 indirect) bytes in 1 blocks are definitely lost in loss record 34 of 37 ==827791== at 0x48435FF: calloc (vg_replace_malloc.c:1117) ==827791== by 0x223D01: zmalloc (macros.h:45) ==827791== by 0x224B79: lttng_trace_chunk_allocate (trace-chunk.c:387) ==827791== by 0x224E41: lttng_trace_chunk_create (trace-chunk.c:427) ==827791== by 0x150B55: session_create_new_trace_chunk (session.c:656) ==827791== by 0x164A11: snapshot_record (cmd.c:5113) ==827791== by 0x1651EE: cmd_snapshot_record (cmd.c:5302) ==827791== by 0x196E74: process_client_msg (client.c:2166) ==827791== by 0x198AF1: thread_manage_clients (client.c:2742) ==827791== by 0x18E245: launch_thread (thread.c:66) ==827791== by 0x4B9E258: start_thread (in /usr/lib/libpthread-2.33.so) ==827791== by 0x4CB45E2: clone (in /usr/lib/libc-2.33.so) session_set_trace_chunk() on line 5162 returns a reference to the current trace chunk which is never released. This also causes tests/regression/tools/snapshots/test_ust_long to fail due to a file descriptor exhaustion (presumably from using too many directory file descriptors) when it is executed by an unprivileged user. The CI doesn't catch this since the long regression test suite is executed as root. Signed-off-by: Jérémie Galarneau Change-Id: I4b6e45df48c3daafa2294c80ccd8a2b4d91401e1 --- src/bin/lttng-sessiond/cmd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 03405bb78..655e4727d 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -4810,6 +4810,9 @@ error_close_trace_chunk: session->name); ret_code = LTTNG_ERR_CLOSE_TRACE_CHUNK_FAIL_CONSUMER; } + + lttng_trace_chunk_put(snapshot_trace_chunk); + snapshot_trace_chunk = NULL; error: if (original_ust_consumer_output) { session->ust_session->consumer = original_ust_consumer_output; -- 2.34.1