client: Plug a race in proxy destruction vs. dispatch
authorDaniel Stone <daniels@collabora.com>
Thu, 28 Dec 2017 16:05:59 +0000 (16:05 +0000)
committerDaniel Stone <daniels@collabora.com>
Tue, 9 Jan 2018 15:19:52 +0000 (15:19 +0000)
commit9744de9f472ec1e3c0e5b3416c097255e3bfdf12
tree4948cc4024b6333d2655e03b1225066aea7a3405
parent430c7820c31608dd29408fc800530b4fd08ff777
client: Plug a race in proxy destruction vs. dispatch

Closures created to hold events which will be dispatched on the client,
take a reference to the proxy for the object the event was sent to, as
well as the proxies for all objects referenced in that event.

These references are dropped immediately before dispatch, with the
display lock also being released. This leaves the potential for a
vanishingly small race, where another thread drops the last reference
on one of the proxies used in an event as it is being dispatched.

Fix this by splitting decrease_closure_args_refcount into two functions:
one which validates the objects (to ensure that clients are not returned
objects which they have destroyed), and another which unrefs all proxies
on the closure (object event was sent to, all referenced objects) as
well as the closure itself. For symmetry, increase_closure_args_refcount
is now the place where the refcount for the proxy for the object the
event was sent to, is increased.

This also happens to fix a bug: previously, if an event was sent to a
client-destroyed object, and the event had object arguments, a reference
would be leaked on the proxy for each of the object arguments.

Found by inspection whilst reviewing the zombie-FD-leak series.

Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
Cc: Jonas Ã…dahl <jadahl@gmail.com>
Cc: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
src/wayland-client.c