From a2853311f3a1d9a6e43bd08efbd960f079431bc0 Mon Sep 17 00:00:00 2001 From: Alexandru Gagniuc Date: Wed, 19 Dec 2012 21:53:51 -0600 Subject: [PATCH] sigrok-cli.c: Fix memory leak in parsing of hardware options During parsing of hardware options, hash_to_hwopt() creates a GSList that is passed to device_scan(). The list is discarded by device_scan() and never freed. This is identified by valgrind as "definitely lost". Call g_slist_free_full() on the list when it is no longer needed. Signed-off-by: Alexandru Gagniuc --- sigrok-cli.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sigrok-cli.c b/sigrok-cli.c index bb9305f..70d3a59 100644 --- a/sigrok-cli.c +++ b/sigrok-cli.c @@ -140,6 +140,12 @@ static GSList *hash_to_hwopt(GHashTable *hash) return opts; } +static void free_hwopt(struct sr_hwopt *hwopt) +{ + g_free((void *)hwopt->value); + g_free(hwopt); +} + static GSList *device_scan(void) { struct sr_dev_driver **drivers, *driver; @@ -174,6 +180,7 @@ static GSList *device_scan(void) /* Unknown options, already logged. */ return NULL; devices = sr_driver_scan(driver, drvopts); + g_slist_free_full(drvopts, (GDestroyNotify)free_hwopt); } else { /* No driver specified, let them all scan on their own. */ devices = NULL; -- 2.30.2