summaryrefslogtreecommitdiffstats
path: root/osdep/terminal-unix.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-06-27 14:22:28 +0200
committerwm4 <wm4@nowhere>2017-06-29 10:31:13 +0200
commitcd25d98bfa38c87bd857264e876cd8be42eb3678 (patch)
treef721ae2930ac3ce823326592f986f4f4c20654e6 /osdep/terminal-unix.c
parent7eca787571aab982acaadee79abb0f40f9f14b6a (diff)
downloadmpv-cd25d98bfa38c87bd857264e876cd8be42eb3678.tar.bz2
mpv-cd25d98bfa38c87bd857264e876cd8be42eb3678.tar.xz
Avoid calling close(-1)
While this is perfectly OK on Unix, it causes annoying valgrind warnings, and might be otherwise confusing to others. On Windows, the runtime can actually abort the process if this is called. push.c part taken from a patch by Pedro Pombeiro.
Diffstat (limited to 'osdep/terminal-unix.c')
-rw-r--r--osdep/terminal-unix.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c
index ffd6ee486c..eca6c69461 100644
--- a/osdep/terminal-unix.c
+++ b/osdep/terminal-unix.c
@@ -368,7 +368,16 @@ static void continue_sighandler(int signum)
static pthread_t input_thread;
static struct input_ctx *input_ctx;
-static int death_pipe[2];
+static int death_pipe[2] = {-1, -1};
+
+static void close_death_pipe(void)
+{
+ for (int n = 0; n < 2; n++) {
+ if (death_pipe[n] >= 0)
+ close(death_pipe[n]);
+ death_pipe[n] = -1;
+ }
+}
static void quit_request_sighandler(int signum)
{
@@ -421,8 +430,7 @@ void terminal_setup_getch(struct input_ctx *ictx)
if (pthread_create(&input_thread, NULL, terminal_thread, NULL)) {
input_ctx = NULL;
- close(death_pipe[0]);
- close(death_pipe[1]);
+ close_death_pipe();
return;
}
@@ -450,8 +458,7 @@ void terminal_uninit(void)
if (input_ctx) {
(void)write(death_pipe[1], &(char){0}, 1);
pthread_join(input_thread, NULL);
- close(death_pipe[0]);
- close(death_pipe[1]);
+ close_death_pipe();
input_ctx = NULL;
}