From: Jérémie Galarneau Date: Tue, 5 Dec 2023 21:06:07 +0000 (-0500) Subject: lttng-ctl: manage memory automatically in kernel tracer status check X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d93bbc2a50cd24ea2837d8710c99b71b5d1a5f11;p=lttng-tools.git lttng-ctl: manage memory automatically in kernel tracer status check Use a unique_ptr to manage the dynamically allocated payload returned by lttng_ctl_ask_sessiond. Signed-off-by: Jérémie Galarneau Change-Id: I685fc03c1da7ff7903503ed82636d27f98f9895e --- diff --git a/src/lib/lttng-ctl/lttng-ctl.cpp b/src/lib/lttng-ctl/lttng-ctl.cpp index 22823d344..96ed7b41b 100644 --- a/src/lib/lttng-ctl/lttng-ctl.cpp +++ b/src/lib/lttng-ctl/lttng-ctl.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -2882,28 +2883,27 @@ end: * * Sets the value of the argument */ -enum lttng_error_code lttng_get_kernel_tracer_status(enum lttng_kernel_tracer_status *status) +enum lttng_error_code lttng_get_kernel_tracer_status(enum lttng_kernel_tracer_status *out_status) { - enum lttng_error_code ret = LTTNG_ERR_INVALID; - - if (status == nullptr) { + if (out_status == nullptr) { return LTTNG_ERR_INVALID; } struct lttcomm_session_msg lsm = {}; lsm.cmd_type = LTTCOMM_SESSIOND_COMMAND_KERNEL_TRACER_STATUS; - uint32_t *u_status = nullptr; - const auto ask_ret = lttng_ctl_ask_sessiond(&lsm, (void **) &u_status); + uint32_t *raw_tracer_status = nullptr; + const auto ask_ret = lttng_ctl_ask_sessiond(&lsm, (void **) &raw_tracer_status); + + const auto tracer_status = + lttng::make_unique_wrapper(raw_tracer_status); + if (ask_ret != 4) { - goto end; + return LTTNG_ERR_INVALID; } - *status = (enum lttng_kernel_tracer_status) * u_status; - ret = LTTNG_OK; -end: - free(u_status); - return ret; + *out_status = (enum lttng_kernel_tracer_status) * tracer_status; + return LTTNG_OK; } /*