There was the sr_channel_new() allocation routine, but releasing that
allocation was open-coded in call sites. Add the sr_channel_free()
routine for code re-use and consistency.
return ch;
}
+/**
+ * Release a previously allocated struct sr_channel.
+ *
+ * @param[in] ch Pointer to struct sr_channel.
+ *
+ * @private
+ */
+SR_PRIV void sr_channel_free(struct sr_channel *ch)
+{
+ if (!ch)
+ return;
+ g_free(ch->name);
+ g_free(ch->priv);
+ g_free(ch);
+}
+
+/**
+ * Wrapper around @ref sr_channel_free(), suitable for glib iterators.
+ */
+SR_PRIV void sr_channel_free_cb(void *p)
+{
+ sr_channel_free(p);
+}
+
/**
* Set the name of the specified channel.
*
for (l = sdi->channels; l; l = l->next) {
ch = l->data;
- g_free(ch->name);
- g_free(ch->priv);
- g_free(ch);
+ sr_channel_free(ch);
}
g_slist_free(sdi->channels);
SR_PRIV struct sr_channel *sr_channel_new(struct sr_dev_inst *sdi,
int index, int type, gboolean enabled, const char *name);
+SR_PRIV void sr_channel_free(struct sr_channel *ch);
+SR_PRIV void sr_channel_free_cb(void *p);
SR_PRIV struct sr_channel *sr_next_enabled_channel(const struct sr_dev_inst *sdi,
struct sr_channel *cur_channel);