From 7d39bfe82be6489760618a918955edcc7e0f1c27 Mon Sep 17 00:00:00 2001 From: Mykyta Holubakha Date: Thu, 7 Apr 2016 18:01:00 +0300 Subject: Close file handles --- brightnessctl.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'brightnessctl.c') 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; -- cgit v1.2.3