sr_serial_dev_inst_free(): Allow NULL as argument.

This commit is contained in:
Uwe Hermann 2017-03-08 19:27:25 +01:00
parent 4bf9398802
commit 04891a997c
4 changed files with 9 additions and 8 deletions

View 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);

View File

@ -323,7 +323,6 @@ 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);
g_free(devc);
sr_dev_inst_free(sdi);

View 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);
}
g_free(devc);
sr_dev_inst_free(sdi);

View File

@ -800,7 +800,6 @@ 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);
return NULL;