From: Gerhard Sittig Date: Thu, 5 Oct 2023 16:11:18 +0000 (+0200) Subject: kingst-la2016: rephrase 'sdi' resource release during scan X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=683f977e266eea4958839c561888f0f96c043ab6;p=libsigrok.git kingst-la2016: rephrase 'sdi' resource release during scan Eliminate an incomplete local copy of sdi resource release code in an error path of scan/probe. Use common code instead to free the sdi. Assign opaque pointers to intermediate variables before passing their values to other routines. Should slightly increase readability and data type safety. Also close the USB handle if it's open at this time. --- diff --git a/src/hardware/kingst-la2016/api.c b/src/hardware/kingst-la2016/api.c index 5f536933..5a4ee6fa 100644 --- a/src/hardware/kingst-la2016/api.c +++ b/src/hardware/kingst-la2016/api.c @@ -198,15 +198,21 @@ static void kingst_la2016_free_devc(struct dev_context *devc) /* Convenience. Release an allocated sdi from error paths. */ static void kingst_la2016_free_sdi(struct sr_dev_inst *sdi) { + struct sr_usb_dev_inst *usb; + struct dev_context *devc; + if (!sdi) return; - g_free(sdi->vendor); - g_free(sdi->model); - g_free(sdi->version); - g_free(sdi->serial_num); - g_free(sdi->connection_id); - sr_usb_dev_inst_free(sdi->conn); - kingst_la2016_free_devc(sdi->priv); + + usb = sdi->conn; + if (usb && usb->devhdl) + sr_usb_close(usb); + sr_usb_dev_inst_free(usb); + + devc = sdi->priv; + kingst_la2016_free_devc(devc); + + sr_dev_inst_free(sdi); } /* Convenience. Open a USB device (including claiming an interface). */