From 29e50127b6f1f998755cd82d4c6731ab8d502e05 Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Wed, 13 May 2015 23:38:56 -0500 Subject: [PATCH] wmbattery: Properly free malloced memory. Fixes memory leak found by cppcheck. --- wmbattery/acpi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wmbattery/acpi.c b/wmbattery/acpi.c index 1e837d2..dc2f3bc 100644 --- a/wmbattery/acpi.c +++ b/wmbattery/acpi.c @@ -188,8 +188,10 @@ int find_items(char *itemname, char infoarray[ACPI_MAXITEM][128], sprintf(pathname, SYSFS_PATH); dir = opendir(pathname); - if (dir == NULL) + if (dir == NULL) { + free(devices); return 0; + } while ((ent = readdir(dir))) { char filename[128]; char buf[1024]; @@ -224,9 +226,9 @@ int find_items(char *itemname, char infoarray[ACPI_MAXITEM][128], acpi_labels[label_info]); snprintf(statusarray[i], sizeof(statusarray[i]), SYSFS_PATH "/%s/%s", devices[i], acpi_labels[label_status]); - free(devices[i]); } + free(devices); return num_devices; }