+struct lttng_channel *lttng_channel_create(struct lttng_domain *domain)
+{
+ struct lttng_channel *channel = NULL;
+ struct lttng_channel_extended *extended = NULL;
+
+ if (!domain) {
+ goto error;
+ }
+
+ /* Validate domain. */
+ switch (domain->type) {
+ case LTTNG_DOMAIN_UST:
+ switch (domain->buf_type) {
+ case LTTNG_BUFFER_PER_UID:
+ case LTTNG_BUFFER_PER_PID:
+ break;
+ default:
+ goto error;
+ }
+ break;
+ case LTTNG_DOMAIN_KERNEL:
+ if (domain->buf_type != LTTNG_BUFFER_GLOBAL) {
+ goto error;
+ }
+ break;
+ default:
+ goto error;
+ }
+
+ channel = zmalloc(sizeof(*channel));
+ if (!channel) {
+ goto error;
+ }
+
+ extended = zmalloc(sizeof(*extended));
+ if (!extended) {
+ goto error;
+ }
+
+ channel->attr.extended.ptr = extended;
+
+ lttng_channel_set_default_attr(domain, &channel->attr);
+ return channel;
+error:
+ free(channel);
+ free(extended);
+ return NULL;
+}
+
+void lttng_channel_destroy(struct lttng_channel *channel)
+{
+ if (!channel) {
+ return;
+ }
+
+ if (channel->attr.extended.ptr) {
+ free(channel->attr.extended.ptr);
+ }
+ free(channel);
+}
+