From: Gerhard Sittig Date: Fri, 9 Feb 2018 17:50:53 +0000 (+0100) Subject: gmc-mh-1x-2x: fix potential memory leak X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=56e9672b118860303bc072c6d5815834d5ce63fc;p=libsigrok.git gmc-mh-1x-2x: fix potential memory leak The scan_2x_bd232() routine used to always prepare one spare context, and filled it in when a device was found, just to allocate another one and continue scanning. Free the last allocated context unconditionally, as it was allocated unconditionally, and never used. This was reported by clang's scan-build. --- diff --git a/src/hardware/gmc-mh-1x-2x/api.c b/src/hardware/gmc-mh-1x-2x/api.c index bfb211d5..f2cbd7b2 100644 --- a/src/hardware/gmc-mh-1x-2x/api.c +++ b/src/hardware/gmc-mh-1x-2x/api.c @@ -300,11 +300,9 @@ static GSList *scan_2x_bd232(struct sr_dev_driver *di, GSList *options) } }; - /* Free last alloc if no device found */ - if (devc->model == METRAHIT_NONE) { - g_free(devc); - sr_dev_inst_free(sdi); - } + /* Free last alloc that was done in preparation. */ + g_free(devc); + sr_dev_inst_free(sdi); return std_scan_complete(di, devices);