Blob Blame History Raw
From 8c253b18369ed02b8fb282970e974cad4de7fab5 Mon Sep 17 00:00:00 2001
From: Benjamin Tissoires <benjamin.tissoires@gmail.com>
Date: Thu, 31 Jan 2013 09:07:54 +1000
Subject: [PATCH] Don't segfault when not using stdout

when using:
$ evemu-record /dev/input/event21 record.txt

And hitting Ctrl-C, the program segfault, because it tries to close two
times the output file descriptor.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
---
 tools/evemu-record.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/evemu-record.c b/tools/evemu-record.c
index 6c5e98d..4417ae1 100644
--- a/tools/evemu-record.c
+++ b/tools/evemu-record.c
@@ -53,8 +53,10 @@ FILE *output;
 static void handler (int sig __attribute__((unused)))
 {
 	fflush(output);
-	if (output != stdout)
+	if (output != stdout) {
 		fclose(output);
+                output = NULL;
+        }
 }
 
 int main(int argc, char *argv[])
@@ -102,7 +104,7 @@ int main(int argc, char *argv[])
 		fprintf(stderr, "error: could not describe device\n");
 	}
 	close(fd);
-	if (output != stdout)
+	if (output && output != stdout)
 		fclose(output);
 	return 0;
 }
-- 
1.8.1