diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2020-10-31 09:36:11 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2020-10-31 09:36:11 +0000 |
| commit | 102d4975a1e9cecb7850f668dc44b52857bf66fe (patch) | |
| tree | 9bbb1734a30ac67dda834b6b3c816dc0c6bd96f7 | |
| parent | Merge branch 'drag-and-drop' (diff) | |
selection: dnd: fix wl_data_offer_destroy() race
At the end of a drag-and-drop operation, we need to call
`wl_data_offer_finish()`.
We *must* ensure the data offer hasn’t been destroyed before
that. This could previously happen if the compositor decided to send a
regular clipboard offer *after* we had started a drop operation,
but *before* it had finished. The dnd offer was then destroyed when
the clipboard offer was received, causing us to crash in
`wl_data_offer_finish()`.
To handle this, let the receive_offer_context take over ownership of
the data_offer pointer, and “manually” destroy it *after* calling
`wl_data_offer_finish()` in `receive_dnd_done()`.
Note: we should not, and can not, do the same thing for regular
clipboard and primary selection offers; such offers can be used
multiple times and should *not* be destroyed after a single copy
operation.
| -rw-r--r-- | selection.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/selection.c b/selection.c index 6e0d8d5a..6767f5fe 100644 --- a/selection.c +++ b/selection.c @@ -1777,6 +1777,7 @@ receive_dnd_done(void *user) struct receive_offer_context *ctx = user; wl_data_offer_finish(ctx->data_offer); + wl_data_offer_destroy(ctx->data_offer); receive_offer_done(user); } @@ -1827,6 +1828,10 @@ drop(void *data, struct wl_data_device *wl_data_device) ? &receive_offer_uri : &receive_offer_text), &receive_dnd_done, ctx); + + /* data offer is now “owned” by the receive context */ + clipboard->data_offer = NULL; + clipboard->mime_type = DATA_OFFER_MIME_UNSET; } static void |
