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>
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;
}