From: Uwe Hermann Date: Wed, 8 Mar 2017 18:18:17 +0000 (+0100) Subject: sr_dev_inst_free(): Allow NULL as argument. X-Git-Tag: libsigrok-0.5.0~95 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=4bf93988023b2428129c8145ef9ea7121400f195 sr_dev_inst_free(): Allow NULL as argument. --- diff --git a/src/device.c b/src/device.c index ace11dd8..38ac003c 100644 --- a/src/device.c +++ b/src/device.c @@ -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); diff --git a/src/hardware/gmc-mh-1x-2x/api.c b/src/hardware/gmc-mh-1x-2x/api.c index 303d435b..2f5d41ed 100644 --- a/src/hardware/gmc-mh-1x-2x/api.c +++ b/src/hardware/gmc-mh-1x-2x/api.c @@ -326,8 +326,7 @@ exit_err: if (serial) sr_serial_dev_inst_free(serial); g_free(devc); - if (sdi) - sr_dev_inst_free(sdi); + sr_dev_inst_free(sdi); return NULL; } diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c index f8fc644c..7bd0b8b4 100644 --- a/src/hardware/hameg-hmo/api.c +++ b/src/hardware/hameg-hmo/api.c @@ -100,8 +100,7 @@ static struct sr_dev_inst *hmo_probe_serial_device(struct sr_scpi_dev_inst *scpi fail: if (hw_info) sr_scpi_hw_info_free(hw_info); - if (sdi) - sr_dev_inst_free(sdi); + sr_dev_inst_free(sdi); g_free(devc); return NULL; diff --git a/src/hardware/lecroy-xstream/api.c b/src/hardware/lecroy-xstream/api.c index 1727ab6d..9dfb0b64 100644 --- a/src/hardware/lecroy-xstream/api.c +++ b/src/hardware/lecroy-xstream/api.c @@ -104,8 +104,7 @@ static struct sr_dev_inst *probe_serial_device(struct sr_scpi_dev_inst *scpi) fail: sr_scpi_hw_info_free(hw_info); - if (sdi) - sr_dev_inst_free(sdi); + sr_dev_inst_free(sdi); g_free(devc); return NULL; diff --git a/src/hardware/motech-lps-30x/api.c b/src/hardware/motech-lps-30x/api.c index de707f2d..68e41393 100644 --- a/src/hardware/motech-lps-30x/api.c +++ b/src/hardware/motech-lps-30x/api.c @@ -488,8 +488,7 @@ exit_err: sr_serial_dev_inst_free(serial); } g_free(devc); - if (sdi) - sr_dev_inst_free(sdi); + sr_dev_inst_free(sdi); return NULL; } diff --git a/src/hardware/rohde-schwarz-sme-0x/api.c b/src/hardware/rohde-schwarz-sme-0x/api.c index 6b84c64a..9d8548ed 100644 --- a/src/hardware/rohde-schwarz-sme-0x/api.c +++ b/src/hardware/rohde-schwarz-sme-0x/api.c @@ -146,10 +146,7 @@ static struct sr_dev_inst *rs_probe_serial_device(struct sr_scpi_dev_inst *scpi) fail: if (hw_info) sr_scpi_hw_info_free(hw_info); - - if (sdi) - sr_dev_inst_free(sdi); - + sr_dev_inst_free(sdi); g_free(devc); return NULL; } diff --git a/src/hardware/yokogawa-dlm/api.c b/src/hardware/yokogawa-dlm/api.c index f8448235..e14e847d 100644 --- a/src/hardware/yokogawa-dlm/api.c +++ b/src/hardware/yokogawa-dlm/api.c @@ -111,8 +111,7 @@ static struct sr_dev_inst *probe_usbtmc_device(struct sr_scpi_dev_inst *scpi) fail: if (hw_info) sr_scpi_hw_info_free(hw_info); - if (sdi) - sr_dev_inst_free(sdi); + sr_dev_inst_free(sdi); g_free(devc); return NULL; diff --git a/src/input/input.c b/src/input/input.c index f99902d3..3db29ffe 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -592,8 +592,7 @@ SR_API void sr_input_free(const struct sr_input *in) if (in->module->cleanup) in->module->cleanup((struct sr_input *)in); - if (in->sdi) - sr_dev_inst_free(in->sdi); + sr_dev_inst_free(in->sdi); if (in->buf->len > 64) { /* That seems more than just some sub-unitsize leftover... */ sr_warn("Found %" G_GSIZE_FORMAT diff --git a/src/lcr/es51919.c b/src/lcr/es51919.c index b80a26c5..8d9d9d96 100644 --- a/src/lcr/es51919.c +++ b/src/lcr/es51919.c @@ -799,8 +799,7 @@ SR_PRIV struct sr_dev_inst *es51919_serial_scan(GSList *options, scan_cleanup: es51919_serial_clean(devc); - if (sdi) - sr_dev_inst_free(sdi); + sr_dev_inst_free(sdi); if (serial) sr_serial_dev_inst_free(serial);