[PATCH 5/6] backlight: Avoid passing an invalid fd into close()

Rob Bradford robert.bradford at intel.com
Thu Jan 10 11:48:56 PST 2013


From: Rob Bradford <rob at linux.intel.com>

---
 src/libbacklight.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/libbacklight.c b/src/libbacklight.c
index add89b2..98a20be 100644
--- a/src/libbacklight.c
+++ b/src/libbacklight.c
@@ -68,7 +68,8 @@ static long backlight_get(struct backlight *backlight, char *node)
 	value = strtol(buffer, NULL, 10);
 	ret = value;
 out:
-	close(fd);
+	if (fd >= 0)
+		close(fd);
 	free(path);
 	return ret;
 }
@@ -124,10 +125,10 @@ long backlight_set_brightness(struct backlight *backlight, long brightness)
 	ret = backlight_get_brightness(backlight);
 	backlight->brightness = ret;
 out:
-	if (buffer)
-		free(buffer);
+	free(buffer);
 	free(path);
-	close(fd);
+	if (fd >= 0)
+		close(fd);
 	return ret;
 }
 
-- 
1.7.11.7



More information about the wayland-devel mailing list