[PATCH evemu 1/2] evemu-record.c: fix memory access in error path
Martin Kepplinger
martink at posteo.de
Fri Sep 15 09:02:20 UTC 2017
In case, for example, the output file could not have been opened, it
is accessed anyways if it's zero, resulting in a segmentation fault.
So let's free resources in the out-path only if they have been allocated
before.
Signed-off-by: Martin Kepplinger <martink at posteo.de>
---
tools/evemu-record.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/tools/evemu-record.c b/tools/evemu-record.c
index 0eaa31d..54c7f92 100644
--- a/tools/evemu-record.c
+++ b/tools/evemu-record.c
@@ -337,9 +337,13 @@ int main(int argc, char *argv[])
rc = 0;
out:
- free(device);
- close(fd);
- if (output != stdout) {
+ if (device)
+ free(device);
+
+ if (fd > 0)
+ close(fd);
+
+ if (output && output != stdout) {
fclose(output);
output = stdout;
}
--
2.11.0
More information about the Input-tools
mailing list