diff options
author | Mykyta Holubakha <hilobakho@gmail.com> | 2016-04-07 18:01:00 +0300 |
---|---|---|
committer | Mykyta Holubakha <hilobakho@gmail.com> | 2016-04-07 18:01:00 +0300 |
commit | 7d39bfe82be6489760618a918955edcc7e0f1c27 (patch) | |
tree | 1a722a705533e634678699ffc2306dad08a78e9c | |
parent | 7ac640201d757c723662fae7aa79021ba6b70bbf (diff) |
Close file handles
-rw-r--r-- | brightnessctl.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/brightnessctl.c b/brightnessctl.c index 2a593df..664be04 100644 --- a/brightnessctl.c +++ b/brightnessctl.c @@ -391,11 +391,11 @@ int save_device_data(struct device *dev) { } if (!S_ISDIR(sb.st_mode)) goto fail; - if (!(fp = fopen(d_path, "w"))) { + if (!(fp = fopen(d_path, "w"))) goto fail; - } if (fwrite(c, 1, s + 1, fp) < s + 1) - goto fail; + errno = -1; + fclose(fp); fail: free(c_path); free(d_path); @@ -414,6 +414,7 @@ int restore_device_data(struct device *dev) { if (!(fp = fopen(filename, "r"))) goto fail; fread(buf, 15, 1, fp); + fclose(fp); dev->curr_brightness = strtol(buf, &end, 10); if (end == buf) errno = -1; |