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 <olivier.gayot@sigexec.com>
This commit is contained in:
Olivier Gayot 2018-06-20 13:41:59 +02:00
parent 445b1925e3
commit c221b4d331

View File

@ -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) {