diff mbox series

[PATH,i-g-t] igt_sysfs: Avoid double closing the fd in igt_sysfs_scanf

Message ID 20180913150613.16265-1-tvrtko.ursulin@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [PATH,i-g-t] igt_sysfs: Avoid double closing the fd in igt_sysfs_scanf | expand

Commit Message

Tvrtko Ursulin Sept. 13, 2018, 3:06 p.m. UTC
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

fdopen takes ownership of the fd so only one flavour of closing it is
needed.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 lib/igt_sysfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Chris Wilson Sept. 13, 2018, 3:20 p.m. UTC | #1
Quoting Tvrtko Ursulin (2018-09-13 16:06:13)
> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> 
> fdopen takes ownership of the fd so only one flavour of closing it is
> needed.

Indeed, I always seem to get burned by this. One day I might remember...
Who am I kidding? :)
 
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
-Chris
diff mbox series

Patch

diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index 9012cc73f6e3..d323b81dd986 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -379,8 +379,9 @@  int igt_sysfs_scanf(int dir, const char *attr, const char *fmt, ...)
 		va_end(ap);
 
 		fclose(file);
+	} else {
+		close(fd);
 	}
-	close(fd);
 
 	return ret;
 }