Fix: sessiond: snapshot: leak of trace chunk
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 3 Nov 2021 02:31:15 +0000 (22:31 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 17 Dec 2021 05:31:09 +0000 (00:31 -0500)
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 <jeremie.galarneau@efficios.com>
Change-Id: I4b6e45df48c3daafa2294c80ccd8a2b4d91401e1

src/bin/lttng-sessiond/cmd.c

index a7990ece4ec524fff33f307f569d0c573a821650..ce468db42df274b0cf1b5d893f3901410c3c3b27 100644 (file)
@@ -5176,6 +5176,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;
This page took 0.02767 seconds and 4 git commands to generate.