diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index 5824804df0..ee6b3e885d 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -583,12 +583,19 @@ static void data_device_handle_drop(void *data, struct wl_data_device *wl_ddev) close(pipefd[1]); wl->dnd_fd = pipefd[0]; - wl_data_offer_finish(wl->dnd_offer); } static void data_device_handle_selection(void *data, struct wl_data_device *wl_ddev, struct wl_data_offer *id) { + struct vo_wayland_state *wl = data; + + if (wl->dnd_offer) { + wl_data_offer_destroy(wl->dnd_offer); + wl->dnd_offer = NULL; + MP_VERBOSE(wl, "Received a new DND offer. Releasing the previous offer."); + } + } static const struct wl_data_device_listener data_device_listener = { @@ -1120,7 +1127,13 @@ static void check_dnd_fd(struct vo_wayland_state *wl) file_list, wl->dnd_action); talloc_free(buffer); end: - talloc_free(wl->dnd_mime_type); + if (wl->dnd_mime_type) + talloc_free(wl->dnd_mime_type); + + if (wl->dnd_action >= 0 && wl->dnd_offer) + wl_data_offer_finish(wl->dnd_offer); + + wl->dnd_action = -1; wl->dnd_mime_type = NULL; wl->dnd_mime_score = 0; }