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;
 }
 
-- 
2.1.4


-- 
To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.

Reply via email to