From ef600041ba1afb84b9caed44f43deb1000651340 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 25 Jul 2014 14:30:59 +0200 Subject: audio, client API: check mp_make_wakeup_pipe() return value Could fail e.g. due to FD exhaustion. --- audio/out/push.c | 12 +++++++----- player/client.c | 7 ++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/audio/out/push.c b/audio/out/push.c index 0ecba19da7..0fb6cb3e29 100644 --- a/audio/out/push.c +++ b/audio/out/push.c @@ -364,17 +364,19 @@ static int init(struct ao *ao) pthread_mutex_init(&p->lock, NULL); pthread_cond_init(&p->wakeup, NULL); pthread_cond_init(&p->wakeup_drain, NULL); - mp_make_wakeup_pipe(p->wakeup_pipe); + if (mp_make_wakeup_pipe(p->wakeup_pipe) < 0) + goto err; p->buffer = mp_audio_buffer_create(ao); mp_audio_buffer_reinit_fmt(p->buffer, ao->format, &ao->channels, ao->samplerate); mp_audio_buffer_preallocate_min(p->buffer, ao->buffer); - if (pthread_create(&p->thread, NULL, playthread, ao)) { - ao->driver->uninit(ao); - return -1; - } + if (pthread_create(&p->thread, NULL, playthread, ao)) + goto err; return 0; +err: + ao->driver->uninit(ao); + return -1; } const struct ao_driver ao_api_push = { diff --git a/player/client.c b/player/client.c index e7a993dd0e..0a64dd855d 100644 --- a/player/client.c +++ b/player/client.c @@ -1331,11 +1331,12 @@ int mpv_get_wakeup_pipe(mpv_handle *ctx) { pthread_mutex_lock(&ctx->wakeup_lock); if (ctx->wakeup_pipe[0] == -1) { - mp_make_wakeup_pipe(ctx->wakeup_pipe); - write(ctx->wakeup_pipe[1], &(char){0}, 1); + if (mp_make_wakeup_pipe(ctx->wakeup_pipe) >= 0) + write(ctx->wakeup_pipe[1], &(char){0}, 1); } + int fd = ctx->wakeup_pipe[0]; pthread_mutex_unlock(&ctx->wakeup_lock); - return ctx->wakeup_pipe[0]; + return fd; } unsigned long mpv_client_api_version(void) -- cgit v1.2.3