From: Uwe Hermann Date: Wed, 8 Mar 2017 18:27:25 +0000 (+0100) Subject: sr_serial_dev_inst_free(): Allow NULL as argument. X-Git-Tag: libsigrok-0.5.0~94 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=04891a997c137abb5fa423e7de7f5b9a0fd27a49;p=libsigrok.git sr_serial_dev_inst_free(): Allow NULL as argument. --- diff --git a/src/device.c b/src/device.c index 38ac003c..71221433 100644 --- a/src/device.c +++ b/src/device.c @@ -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); diff --git a/src/hardware/gmc-mh-1x-2x/api.c b/src/hardware/gmc-mh-1x-2x/api.c index 2f5d41ed..801429ce 100644 --- a/src/hardware/gmc-mh-1x-2x/api.c +++ b/src/hardware/gmc-mh-1x-2x/api.c @@ -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); diff --git a/src/hardware/motech-lps-30x/api.c b/src/hardware/motech-lps-30x/api.c index 68e41393..4ec35ff5 100644 --- a/src/hardware/motech-lps-30x/api.c +++ b/src/hardware/motech-lps-30x/api.c @@ -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); diff --git a/src/lcr/es51919.c b/src/lcr/es51919.c index 8d9d9d96..3a987c62 100644 --- a/src/lcr/es51919.c +++ b/src/lcr/es51919.c @@ -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; }