]> git.lttng.org Git - lttng-tools.git/commitdiff
Clean-up: sessiond: enable_event: use unique_ptr to manage memory
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 26 Nov 2024 15:07:53 +0000 (15:07 +0000)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 26 Nov 2024 17:05:50 +0000 (17:05 +0000)
Simplify the error paths used to create the internal events associated
with agent events as copies of the filter bytecode and expressions are
performed.

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

index 425b552f49ab1ad9699fdb136b2886a163538c63..e789a9891635841090f588dd6a306e059bcd50a4 100644 (file)
@@ -2706,23 +2706,24 @@ static lttng_error_code _cmd_enable_event(ltt_session::locked_ref& locked_sessio
                user_visible_channel_name = default_chan_name;
 
                {
-                       char *filter_expression_copy = nullptr;
-                       struct lttng_bytecode *bytecode_copy = nullptr;
+                       auto filter_expression_copy =
+                               lttng::make_unique_wrapper<char, lttng::memory::free>();
+                       auto bytecode_copy =
+                               lttng::make_unique_wrapper<lttng_bytecode, lttng::memory::free>();
 
                        if (bytecode) {
                                const size_t filter_size =
                                        sizeof(struct lttng_bytecode) + bytecode->len;
 
-                               bytecode_copy = zmalloc<lttng_bytecode>(filter_size);
+                               bytecode_copy.reset(zmalloc<lttng_bytecode>(filter_size));
                                if (!bytecode_copy) {
                                        return LTTNG_ERR_NOMEM;
                                }
 
-                               memcpy(bytecode_copy, bytecode.get(), filter_size);
+                               memcpy(bytecode_copy.get(), bytecode.get(), filter_size);
 
-                               filter_expression_copy = strdup(filter_expression.get());
+                               filter_expression_copy.reset(strdup(filter_expression.get()));
                                if (!filter_expression_copy) {
-                                       free(bytecode_copy);
                                        return LTTNG_ERR_NOMEM;
                                }
                        }
@@ -2731,8 +2732,8 @@ static lttng_error_code _cmd_enable_event(ltt_session::locked_ref& locked_sessio
                                                        &tmp_dom,
                                                        (char *) default_chan_name,
                                                        &uevent,
-                                                       filter_expression_copy,
-                                                       bytecode_copy,
+                                                       filter_expression_copy.release(),
+                                                       bytecode_copy.release(),
                                                        nullptr,
                                                        wpipe,
                                                        std::move(internal_event_rule));
This page took 0.031806 seconds and 4 git commands to generate.