]> git.lttng.org Git - lttng-tools.git/commitdiff
Fix: sessiond: cmd_add_ctx: leak of internal channel members
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 26 Nov 2024 15:27:10 +0000 (15:27 +0000)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 26 Nov 2024 17:05:50 +0000 (17:05 +0000)
lttng_channel instances must be released using channel_attr_destroy.
However, an error path of cmd_add_ctx uses free() directly, which causes
internal structures of lttng_channel to be leaked.

Wrap the lttng_channel instance to use a unique_ptr which invokes
channel_attr_destroy on release.

Change-Id: I77443c8a57475437dbb11792869e70840680492f
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/cmd.cpp

index e789a9891635841090f588dd6a306e059bcd50a4..a5bf81f8911d9f3ed878115efd91c681a9d65477 100644 (file)
@@ -2254,20 +2254,20 @@ int cmd_add_context(struct command_ctx *cmd_ctx,
 
                chan_count = lttng_ht_get_count(usess->domain_global.channels);
                if (chan_count == 0) {
-                       struct lttng_channel *attr;
                        /* Create default channel */
-                       attr = channel_new_default_attr(domain, usess->buffer_type);
-                       if (attr == nullptr) {
+                       auto attr = lttng::make_unique_wrapper<lttng_channel, channel_attr_destroy>(
+                               channel_new_default_attr(domain, usess->buffer_type));
+
+                       if (!attr) {
                                ret = LTTNG_ERR_FATAL;
                                goto error;
                        }
 
-                       ret = channel_ust_create(usess, attr, usess->buffer_type);
+                       ret = channel_ust_create(usess, attr.get(), usess->buffer_type);
                        if (ret != LTTNG_OK) {
-                               free(attr);
                                goto error;
                        }
-                       channel_attr_destroy(attr);
+
                        chan_ust_created = 1;
                }
 
This page took 0.031175 seconds and 4 git commands to generate.