summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-02-28 01:03:37 +0100
committerwm4 <wm4@nowhere>2014-02-28 01:03:37 +0100
commit1852555ca1100e06e970a9c9703ebcb045ff6006 (patch)
treef640a356f5d399e3716191ec8a5aafdb35bd2dc1
parent6b2a929ca7743da84148b18ed6519ce91d0b9680 (diff)
downloadmpv-1852555ca1100e06e970a9c9703ebcb045ff6006.tar.bz2
mpv-1852555ca1100e06e970a9c9703ebcb045ff6006.tar.xz
client API: wait for remaining asynchronous requests before terminating
Sending an asynchronous request and then calling mpv_destroy() would crash the player when trying to send the reply to the removed client. Fix this by waiting until all remaining replies have been sent.
-rw-r--r--player/client.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/player/client.c b/player/client.c
index 778070f266..c1e665a9fb 100644
--- a/player/client.c
+++ b/player/client.c
@@ -191,6 +191,15 @@ void mpv_destroy(mpv_handle *ctx)
if (!ctx)
return;
+ pthread_mutex_lock(&ctx->lock);
+ // reserved_events equals the number of asynchronous requests that weren't
+ // yet replied. In order to avoid that trying to reply to a removed event
+ // causes a crash, block until all asynchronous requests were served.
+ ctx->event_mask = 0;
+ while (ctx->reserved_events)
+ pthread_cond_wait(&ctx->wakeup, &ctx->lock);
+ pthread_mutex_unlock(&ctx->lock);
+
struct mp_client_api *clients = ctx->clients;
pthread_mutex_lock(&clients->lock);