1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-11 08:37:59 +00:00

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.
This commit is contained in:
wm4 2014-02-28 01:03:37 +01:00
parent 6b2a929ca7
commit 1852555ca1

View File

@ -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);