sigrok-cli: Fix leaks in device_scan().
authorpoljar (Damir Jelić) <poljarinho@gmail.com>
Wed, 30 Oct 2013 22:04:02 +0000 (23:04 +0100)
committerBert Vermeulen <bert@biot.com>
Thu, 31 Oct 2013 08:47:37 +0000 (09:47 +0100)
If a bogus driver name is specified on the command line or for some reason we
fail to initialize a driver device_scan() leaks data.

This patch adds appropriate free calls.

sigrok-cli.c

index c60d3bb1bb144a46be5e139ec38ce8e3f1b1f11a..dbe0b2cdecd3c2d297c0b7686ddece50dbd23bd4 100644 (file)
@@ -178,11 +178,14 @@ static GSList *device_scan(void)
                }
                if (!driver) {
                        g_critical("Driver %s not found.", drvname);
+                       g_hash_table_destroy(drvargs);
+                       g_free(drvname);
                        return NULL;
                }
                g_free(drvname);
                if (sr_driver_init(sr_ctx, driver) != SR_OK) {
                        g_critical("Failed to initialize driver.");
+                       g_hash_table_destroy(drvargs);
                        return NULL;
                }
                drvopts = NULL;
@@ -193,7 +196,7 @@ static GSList *device_scan(void)
                                return NULL;
                        }
                }
-               g_hash_table_destroy(drvargs); 
+               g_hash_table_destroy(drvargs);
                devices = sr_driver_scan(driver, drvopts);
                g_slist_free_full(drvopts, (GDestroyNotify)free_drvopts);
        } else {