device: introduce common sr_channel_free() support code
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.
This commit is contained in:
parent
4237ab9e5b
commit
fe71c7e42e
28
src/device.c
28
src/device.c
|
@ -73,6 +73,30 @@ SR_PRIV struct sr_channel *sr_channel_new(struct sr_dev_inst *sdi,
|
|||
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.
|
||||
*
|
||||
|
@ -364,9 +388,7 @@ SR_PRIV void sr_dev_inst_free(struct sr_dev_inst *sdi)
|
|||
|
||||
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);
|
||||
|
||||
|
|
|
@ -782,6 +782,8 @@ enum {
|
|||
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue