aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <dbphillipsnz@gmail.com>2015-11-20 14:05:22 +1300
committerDavid Phillips <dbphillipsnz@gmail.com>2015-11-20 14:11:34 +1300
commitc239a8bf0767a31ca87d3d3cecc3006789992753 (patch)
treed0c408050ebbfc6bf000b66974291be6ab79eab7
parentc9265161f88c5a602fdd56131334e492ff18dcc7 (diff)
downloadparamano-c239a8bf0767a31ca87d3d3cecc3006789992753.tar.xz
Fixed hanging fd on battery status read failure
-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);