summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Gayot <olivier.gayot@sigexec.com>2018-06-20 11:58:10 +0200
committerOlivier Gayot <olivier.gayot@sigexec.com>2018-06-20 14:20:17 +0200
commit445b1925e3d2e239740d7765e5892d0671174e8e (patch)
tree8514f24a66a7cf6aacc53ec25386a0b2e1f9450f
parentc64195d14728aa82e280d022e9f7ceff71cfc6c1 (diff)
Fix potential memory leak on Linux
The function slurp_all_batteries(), on Linux, allocates memory dynamically Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
-rw-r--r--src/print_battery_info.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/print_battery_info.c b/src/print_battery_info.c
index 7a462f7..72c2d6f 100644
--- a/src/print_battery_info.c
+++ b/src/print_battery_info.c
@@ -450,8 +450,11 @@ static bool slurp_all_batteries(struct battery_info *batt_info, yajl_gen json_ge
.present_rate = 0,
.status = CS_UNKNOWN,
};
- if (!slurp_battery_info(&batt_buf, json_gen, buffer, i, globbuf.gl_pathv[i], format_down))
+ if (!slurp_battery_info(&batt_buf, json_gen, buffer, i, globbuf.gl_pathv[i], format_down)) {
+ globfree(&globbuf);
+ free(globpath);
return false;
+ }
is_found = true;
add_battery_info(batt_info, &batt_buf);