linux/Battery.c: make sure fd is always closed

Detected by Coverity:
https://scan8.coverity.com/reports.htm#v13252/p10402/fileInstanceId=22093957&defectInstanceId=7543348&mergedDefectId=174180
This commit is contained in:
Hisham Muhammad 2018-02-18 10:21:22 -03:00
parent ff78a1bfce
commit b064d501ae
1 changed files with 1 additions and 4 deletions

View File

@ -110,16 +110,13 @@ static ACPresence procAcpiCheck() {
char statePath[50]; char statePath[50];
xSnprintf((char *) statePath, sizeof statePath, "%s/%s/state", power_supplyPath, entryName); xSnprintf((char *) statePath, sizeof statePath, "%s/%s/state", power_supplyPath, entryName);
FILE* file = fopen(statePath, "r"); FILE* file = fopen(statePath, "r");
if (!file) { if (!file) {
isOn = AC_ERROR; isOn = AC_ERROR;
continue; continue;
} }
char* line = String_readLine(file); char* line = String_readLine(file);
if (!line) continue;
fclose(file); fclose(file);
if (!line) continue;
const char *isOnline = String_getToken(line, 2); const char *isOnline = String_getToken(line, 2);
free(line); free(line);