From 1852555ca1100e06e970a9c9703ebcb045ff6006 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 28 Feb 2014 01:03:37 +0100 Subject: 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. --- player/client.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'player') 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); -- cgit v1.2.3