lttng_trigger_create_from_payload() leaks its newly-created
trigger when it fails to set the trigger's name. Drop
the reference to the new trigger whenever the function fails.
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I9dbf91d404fd67e4b79f2af550f3768680d6d4ec
LTTNG_HIDDEN
ssize_t lttng_trigger_create_from_payload(
struct lttng_payload_view *src_view,
LTTNG_HIDDEN
ssize_t lttng_trigger_create_from_payload(
struct lttng_payload_view *src_view,
- struct lttng_trigger **trigger)
+ struct lttng_trigger **_trigger)
{
ssize_t ret, offset = 0, condition_size, action_size, name_size = 0;
struct lttng_condition *condition = NULL;
{
ssize_t ret, offset = 0, condition_size, action_size, name_size = 0;
struct lttng_condition *condition = NULL;
.uid = LTTNG_OPTIONAL_INIT_UNSET,
.gid = LTTNG_OPTIONAL_INIT_UNSET,
};
.uid = LTTNG_OPTIONAL_INIT_UNSET,
.gid = LTTNG_OPTIONAL_INIT_UNSET,
};
+ struct lttng_trigger *trigger = NULL;
const struct lttng_payload_view trigger_comm_view =
lttng_payload_view_from_view(
src_view, 0, sizeof(*trigger_comm));
const struct lttng_payload_view trigger_comm_view =
lttng_payload_view_from_view(
src_view, 0, sizeof(*trigger_comm));
- if (!src_view || !trigger) {
+ if (!src_view || !_trigger) {
- *trigger = lttng_trigger_create(condition, action);
- if (!*trigger) {
+ trigger = lttng_trigger_create(condition, action);
+ if (!trigger) {
- lttng_trigger_set_credentials(*trigger, &creds);
+ lttng_trigger_set_credentials(trigger, &creds);
/*
* The trigger object owns references to the action and condition
/*
* The trigger object owns references to the action and condition
if (name) {
const enum lttng_trigger_status status =
if (name) {
const enum lttng_trigger_status status =
- lttng_trigger_set_name(*trigger, name);
+ lttng_trigger_set_name(trigger, name);
if (status != LTTNG_TRIGGER_STATUS_OK) {
ret = -1;
if (status != LTTNG_TRIGGER_STATUS_OK) {
ret = -1;
lttng_condition_put(condition);
lttng_action_put(action);
end:
lttng_condition_put(condition);
lttng_action_put(action);
end:
+ if (ret == 0) {
+ *_trigger = trigger;
+ } else {
+ lttng_trigger_put(trigger);
+ }
+