aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bat_tray.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/bat_tray.c b/bat_tray.c
index f7c4a4c..254cf97 100644
--- a/bat_tray.c
+++ b/bat_tray.c
@@ -235,10 +235,15 @@ int get_battery_state()
char state[1024];
FILE* fd = NULL;
- if (!(fd = fopen(CHARGE_STATE_PATH, "r")) ||
- !fgets(state, sizeof(state), fd))
+ if (!(fd = fopen(CHARGE_STATE_PATH, "r")))
return STATE_UNKNOWN;
+ if (!fgets(state, sizeof(state), fd))
+ {
+ fclose(fd);
+ return STATE_UNKNOWN;
+ }
+
fclose(fd);
chomp(state);