From c221b4d331d46d07fe24afc78e4eeb021556d013 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Wed, 20 Jun 2018 13:41:59 +0200 Subject: [PATCH] Prevent potential crash if glob() fails Calling globfree(NULL) is undefined behaviour. In Linux (glibc), it results in a segmentation fault. It is also undefined behaviour to call globfree(&pglob) if a previous call to glob(&pglob) returned an error. Signed-off-by: Olivier Gayot --- src/print_battery_info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/print_battery_info.c b/src/print_battery_info.c index 72c2d6f..04b5a25 100644 --- a/src/print_battery_info.c +++ b/src/print_battery_info.c @@ -459,8 +459,8 @@ static bool slurp_all_batteries(struct battery_info *batt_info, yajl_gen json_ge is_found = true; add_battery_info(batt_info, &batt_buf); } + globfree(&globbuf); } - globfree(&globbuf); free(globpath); if (!is_found) { -- 2.39.5