X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fdevice.c;h=9dd2201e528b05a0848a4cf0e34135dd7232fde9;hb=HEAD;hp=5a450fad7ad5f186ab0facdcfd9f84db18e3c2a4;hpb=1e7468a8858768806a066f52d47d167a3721a8e4;p=libsigrok.git diff --git a/src/device.c b/src/device.c index 5a450fad..5c681378 100644 --- a/src/device.c +++ b/src/device.c @@ -67,7 +67,7 @@ SR_PRIV struct sr_channel *sr_channel_new(struct sr_dev_inst *sdi, ch->index = index; ch->type = type; ch->enabled = enabled; - if (name) + if (name && *name) ch->name = g_strdup(name); sdi->channels = g_slist_append(sdi->channels, ch); @@ -120,6 +120,8 @@ SR_API int sr_dev_channel_name_set(struct sr_channel *channel, { if (!channel) return SR_ERR_ARG; + if (!name || !*name) + return SR_ERR_ARG; g_free(channel->name); channel->name = g_strdup(name); @@ -489,7 +491,8 @@ SR_API int sr_dev_inst_channel_add(struct sr_dev_inst *sdi, int index, int type, if (!sdi || sdi->inst_type != SR_INST_USER || index < 0) return SR_ERR_ARG; - sr_channel_new(sdi, index, type, TRUE, name); + if (!sr_channel_new(sdi, index, type, TRUE, name)) + return SR_ERR_DATA; return SR_OK; } @@ -566,6 +569,15 @@ SR_PRIV void sr_usb_dev_inst_free(struct sr_usb_dev_inst *usb) g_free(usb); } +/** + * Wrapper for g_slist_free_full() convenience. + * + * @private + */ +SR_PRIV void sr_usb_dev_inst_free_cb(gpointer p) +{ + sr_usb_dev_inst_free(p); +} #endif #ifdef HAVE_SERIAL_COMM