]> sigrok.org Git - libsigrok.git/blobdiff - src/device.c
sr_serial_dev_inst_free(): Allow NULL as argument.
[libsigrok.git] / src / device.c
index ace11dd86204b178a63ef903b7006c889ddd8661..71221433ca0321c1ee6ca95fbab3cf335448885a 100644 (file)
@@ -339,7 +339,7 @@ SR_API int sr_dev_inst_channel_add(struct sr_dev_inst *sdi, int index, int type,
 /**
  * Free device instance struct created by sr_dev_inst().
  *
- * @param sdi Device instance to free. Must not be NULL.
+ * @param sdi Device instance to free. If NULL, the function will do nothing.
  *
  * @private
  */
@@ -349,6 +349,9 @@ SR_PRIV void sr_dev_inst_free(struct sr_dev_inst *sdi)
        struct sr_channel_group *cg;
        GSList *l;
 
+       if (!sdi)
+               return;
+
        for (l = sdi->channels; l; l = l->next) {
                ch = l->data;
                g_free(ch->name);
@@ -454,12 +457,16 @@ SR_PRIV struct sr_serial_dev_inst *sr_serial_dev_inst_new(const char *port,
 /**
  * Free struct sr_serial_dev_inst * allocated by sr_serial_dev_inst().
  *
- * @param serial The struct sr_serial_dev_inst * to free. Must not be NULL.
+ * @param serial The struct sr_serial_dev_inst * to free. If NULL, this
+ *               function will do nothing.
  *
  * @private
  */
 SR_PRIV void sr_serial_dev_inst_free(struct sr_serial_dev_inst *serial)
 {
+       if (!serial)
+               return;
+
        g_free(serial->port);
        g_free(serial->serialcomm);
        g_free(serial);