From: Lars-Peter Clausen Date: Sun, 15 May 2016 15:20:51 +0000 (+0200) Subject: Don't reset instance list in scan() callback X-Git-Tag: libsigrok-0.5.0~369 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=566007e15e8ec0a23b064ba8ea44baae305508b5;p=libsigrok.git Don't reset instance list in scan() callback Some drivers set the device instance list to NULL in their scan() callback. This means the driver loses all references to any devices contained in that list and their resources will be leaked. Drivers can't free the devices at this point either since an application might still use a device on the list. So the existing devices on the instance list need to remain unmodified during the scan() callback, even if that means that there will be duplicates on the instance list. Only an explicit invocation of sr_dev_clear() by the application is allowed to free the devices on the instance list and reset the list. Signed-off-by: Lars-Peter Clausen --- diff --git a/src/hardware/agilent-dmm/api.c b/src/hardware/agilent-dmm/api.c index 514a2d27..78e7efe8 100644 --- a/src/hardware/agilent-dmm/api.c +++ b/src/hardware/agilent-dmm/api.c @@ -83,7 +83,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) char *buf, **tokens; drvc = di->context; - drvc->instances = NULL; devices = NULL; conn = serialcomm = NULL; diff --git a/src/hardware/appa-55ii/api.c b/src/hardware/appa-55ii/api.c index d6c5d6a9..c5700011 100644 --- a/src/hardware/appa-55ii/api.c +++ b/src/hardware/appa-55ii/api.c @@ -81,7 +81,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) sr_info("Probing serial port %s.", conn); drvc = di->context; - drvc->instances = NULL; serial_flush(serial); /* Let's get a bit of data and see if we can find a packet. */ diff --git a/src/hardware/arachnid-labs-re-load-pro/api.c b/src/hardware/arachnid-labs-re-load-pro/api.c index aeacda10..6deb6815 100644 --- a/src/hardware/arachnid-labs-re-load-pro/api.c +++ b/src/hardware/arachnid-labs-re-load-pro/api.c @@ -74,7 +74,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) devices = NULL; drvc = di->context; - drvc->instances = NULL; conn = serialcomm = NULL; for (l = options; l; l = l->next) { diff --git a/src/hardware/atten-pps3xxx/api.c b/src/hardware/atten-pps3xxx/api.c index e1ec5f0b..7fd3b678 100644 --- a/src/hardware/atten-pps3xxx/api.c +++ b/src/hardware/atten-pps3xxx/api.c @@ -94,7 +94,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options, int modelid) devices = NULL; drvc = di->context; - drvc->instances = NULL; conn = serialcomm = NULL; for (l = options; l; l = l->next) { diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index 6deafb81..10f9a0fb 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -82,7 +82,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) devices = NULL; drvc = di->context; - drvc->instances = NULL; /* Probe for /dev/beaglelogic */ if (!g_file_test(BEAGLELOGIC_DEV_NODE, G_FILE_TEST_EXISTS)) diff --git a/src/hardware/brymen-bm86x/api.c b/src/hardware/brymen-bm86x/api.c index eb41b845..64acf323 100644 --- a/src/hardware/brymen-bm86x/api.c +++ b/src/hardware/brymen-bm86x/api.c @@ -44,7 +44,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) const char *conn; drvc = di->context; - drvc->instances = NULL; conn = BRYMEN_BC86X; for (l = options; l; l = l->next) { diff --git a/src/hardware/brymen-dmm/api.c b/src/hardware/brymen-dmm/api.c index 595ea99b..0e9034d3 100644 --- a/src/hardware/brymen-dmm/api.c +++ b/src/hardware/brymen-dmm/api.c @@ -97,7 +97,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) devices = NULL; drvc = di->context; - drvc->instances = NULL; conn = serialcomm = NULL; for (l = options; l; l = l->next) { diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index 5c58e4f9..d1a7ec71 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -149,7 +149,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) char product[64], serial_num[64], connection_id[64]; drvc = di->context; - drvc->instances = NULL; conn = NULL; for (l = options; l; l = l->next) { diff --git a/src/hardware/colead-slm/api.c b/src/hardware/colead-slm/api.c index bbb6a957..bc59fd63 100644 --- a/src/hardware/colead-slm/api.c +++ b/src/hardware/colead-slm/api.c @@ -52,7 +52,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) const char *conn, *serialcomm; drvc = di->context; - drvc->instances = NULL; devices = NULL; diff --git a/src/hardware/conrad-digi-35-cpu/api.c b/src/hardware/conrad-digi-35-cpu/api.c index 63c0e4f1..44f9f266 100644 --- a/src/hardware/conrad-digi-35-cpu/api.c +++ b/src/hardware/conrad-digi-35-cpu/api.c @@ -50,7 +50,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) devices = NULL; drvc = di->context; - drvc->instances = NULL; conn = serialcomm = NULL; for (l = options; l; l = l->next) { diff --git a/src/hardware/ftdi-la/api.c b/src/hardware/ftdi-la/api.c index 7bf0e13d..5f5639f9 100644 --- a/src/hardware/ftdi-la/api.c +++ b/src/hardware/ftdi-la/api.c @@ -209,7 +209,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) int i; drvc = di->context; - drvc->instances = NULL; conn = NULL; for (l = options; l; l = l->next) { src = l->data; diff --git a/src/hardware/gmc-mh-1x-2x/api.c b/src/hardware/gmc-mh-1x-2x/api.c index 629a3f2b..7ba93e4e 100644 --- a/src/hardware/gmc-mh-1x-2x/api.c +++ b/src/hardware/gmc-mh-1x-2x/api.c @@ -155,7 +155,6 @@ static GSList *scan_1x_2x_rs232(struct sr_dev_driver *di, GSList *options) devices = NULL; drvc = di->context; - drvc->instances = NULL; conn = serialcomm = NULL; serialcomm_given = FALSE; @@ -249,7 +248,6 @@ static GSList *scan_2x_bd232(struct sr_dev_driver *di, GSList *options) devices = NULL; drvc = di->context; - drvc->instances = NULL; sr_spew("scan_2x_bd232() called!"); diff --git a/src/hardware/ikalogic-scanalogic2/api.c b/src/hardware/ikalogic-scanalogic2/api.c index c30c605c..0c6b8987 100644 --- a/src/hardware/ikalogic-scanalogic2/api.c +++ b/src/hardware/ikalogic-scanalogic2/api.c @@ -67,7 +67,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) devices = NULL; drvc = di->context; - drvc->instances = NULL; usb_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, USB_VID_PID); diff --git a/src/hardware/kecheng-kc-330b/api.c b/src/hardware/kecheng-kc-330b/api.c index f67d2532..fcd08eca 100644 --- a/src/hardware/kecheng-kc-330b/api.c +++ b/src/hardware/kecheng-kc-330b/api.c @@ -112,7 +112,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) (void)options; drvc = di->context; - drvc->instances = NULL; devices = NULL; if ((usb_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, USB_CONN))) { diff --git a/src/hardware/korad-kaxxxxp/api.c b/src/hardware/korad-kaxxxxp/api.c index 02abc7ca..bd80b6e1 100644 --- a/src/hardware/korad-kaxxxxp/api.c +++ b/src/hardware/korad-kaxxxxp/api.c @@ -79,7 +79,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) conn = NULL; serialcomm = NULL; drvc = di->context; - drvc->instances = NULL; for (l = options; l; l = l->next) { src = l->data; diff --git a/src/hardware/lecroy-logicstudio/api.c b/src/hardware/lecroy-logicstudio/api.c index 20ffcf2f..69852b28 100644 --- a/src/hardware/lecroy-logicstudio/api.c +++ b/src/hardware/lecroy-logicstudio/api.c @@ -120,7 +120,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) (void)options; drvc = di->context; - drvc->instances = NULL; devices = NULL; diff --git a/src/hardware/manson-hcs-3xxx/api.c b/src/hardware/manson-hcs-3xxx/api.c index 52695b0b..0b0a053e 100644 --- a/src/hardware/manson-hcs-3xxx/api.c +++ b/src/hardware/manson-hcs-3xxx/api.c @@ -86,7 +86,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) char reply[50], **tokens, *dummy; drvc = di->context; - drvc->instances = NULL; devices = NULL; conn = NULL; serialcomm = NULL; diff --git a/src/hardware/motech-lps-30x/api.c b/src/hardware/motech-lps-30x/api.c index 1c5e3876..ce3294e9 100644 --- a/src/hardware/motech-lps-30x/api.c +++ b/src/hardware/motech-lps-30x/api.c @@ -384,7 +384,6 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o devices = NULL; drvc = drv->context; - drvc->instances = NULL; sr_spew("scan() called!"); diff --git a/src/hardware/norma-dmm/api.c b/src/hardware/norma-dmm/api.c index ee1c59ca..024bcaed 100644 --- a/src/hardware/norma-dmm/api.c +++ b/src/hardware/norma-dmm/api.c @@ -80,7 +80,6 @@ static GSList *scan(struct sr_dev_driver *drv, GSList *options) devices = NULL; drvc = drv->context; - drvc->instances = NULL; conn = serialcomm = NULL; for (l = options; l; l = l->next) { diff --git a/src/hardware/teleinfo/api.c b/src/hardware/teleinfo/api.c index f05db75a..f5920c5b 100644 --- a/src/hardware/teleinfo/api.c +++ b/src/hardware/teleinfo/api.c @@ -74,7 +74,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) sr_info("Probing serial port %s.", conn); drvc = di->context; - drvc->instances = NULL; serial_flush(serial); /* Let's get a bit of data and see if we can find a packet. */ diff --git a/src/hardware/testo/api.c b/src/hardware/testo/api.c index 8e60f6b8..505df675 100644 --- a/src/hardware/testo/api.c +++ b/src/hardware/testo/api.c @@ -58,7 +58,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) devices = NULL; drvc = di->context; - drvc->instances = NULL; conn_devices = NULL; for (l = options; l; l = l->next) { diff --git a/src/hardware/tondaj-sl-814/api.c b/src/hardware/tondaj-sl-814/api.c index f647b6a9..d79bc03d 100644 --- a/src/hardware/tondaj-sl-814/api.c +++ b/src/hardware/tondaj-sl-814/api.c @@ -50,7 +50,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) struct sr_serial_dev_inst *serial; drvc = di->context; - drvc->instances = NULL; devices = NULL; diff --git a/src/hardware/uni-t-ut32x/api.c b/src/hardware/uni-t-ut32x/api.c index 789b72de..147ac7df 100644 --- a/src/hardware/uni-t-ut32x/api.c +++ b/src/hardware/uni-t-ut32x/api.c @@ -48,7 +48,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) const char *conn; drvc = di->context; - drvc->instances = NULL; conn = NULL; for (l = options; l; l = l->next) {