]> sigrok.org Git - libsigrok.git/commitdiff
sr_serial_dev_inst_free(): Allow NULL as argument.
authorUwe Hermann <redacted>
Wed, 8 Mar 2017 18:27:25 +0000 (19:27 +0100)
committerUwe Hermann <redacted>
Fri, 10 Mar 2017 10:41:34 +0000 (11:41 +0100)
src/device.c
src/hardware/gmc-mh-1x-2x/api.c
src/hardware/motech-lps-30x/api.c
src/lcr/es51919.c

index 38ac003cf01d7433b9c1767ccf3ace01d70329db..71221433ca0321c1ee6ca95fbab3cf335448885a 100644 (file)
@@ -457,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);
index 2f5d41edb9ee87060f9f196ca1ca475a81412fcb..801429ce65c942dc8ba1bbb15f3bf12ab60d836c 100644 (file)
@@ -323,8 +323,7 @@ static GSList *scan_2x_bd232(struct sr_dev_driver *di, GSList *options)
 exit_err:
        sr_info("scan_2x_bd232(): Error!");
 
-       if (serial)
-               sr_serial_dev_inst_free(serial);
+       sr_serial_dev_inst_free(serial);
        g_free(devc);
        sr_dev_inst_free(sdi);
 
index 68e4139373073f8ef917081eb4270c2591566523..4ec35ff58f35b3a203c7edfd2b7928e7e399bb67 100644 (file)
@@ -483,10 +483,9 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
 exit_err:
        sr_info("%s: Error!", __func__);
 
-       if (serial) {
+       if (serial)
                serial_close(serial);
-               sr_serial_dev_inst_free(serial);
-       }
+       sr_serial_dev_inst_free(serial);
        g_free(devc);
        sr_dev_inst_free(sdi);
 
index 8d9d9d96476c8e22870baeb06eb4219936484f2b..3a987c626928c1a62b1953077713383fa18b5bf0 100644 (file)
@@ -800,8 +800,7 @@ SR_PRIV struct sr_dev_inst *es51919_serial_scan(GSList *options,
 scan_cleanup:
        es51919_serial_clean(devc);
        sr_dev_inst_free(sdi);
-       if (serial)
-               sr_serial_dev_inst_free(serial);
+       sr_serial_dev_inst_free(serial);
 
        return NULL;
 }