From d5055ad913f4913c1bb1c17cef55049e30c191ad Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 22 Jul 2019 19:41:22 +0300 Subject: [PATCH] server: add wl_global_set_user_data When implementing a workaround for [1], one needs to accept a global to be bound even though it has become stale. Often, a global's user data is free'd when the global needs to be destroyed. Being able to set the global's user data (e.g. to NULL) can help preventing a use-after-free. (The alternative is to make the compositor responsible for keeping track of stale user data objects via e.g. refcounting.) [1]: https://gitlab.freedesktop.org/wayland/wayland/issues/10 Signed-off-by: Simon Ser --- src/wayland-server-core.h | 3 +++ src/wayland-server.c | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/wayland-server-core.h b/src/wayland-server-core.h index 3e0272b..68d7ddb 100644 --- a/src/wayland-server-core.h +++ b/src/wayland-server-core.h @@ -279,6 +279,9 @@ wl_global_get_interface(const struct wl_global *global); void * wl_global_get_user_data(const struct wl_global *global); +void +wl_global_set_user_data(struct wl_global *global, void *data); + struct wl_client * wl_client_create(struct wl_display *display, int fd); diff --git a/src/wayland-server.c b/src/wayland-server.c index 11cb7f5..8c537bb 100644 --- a/src/wayland-server.c +++ b/src/wayland-server.c @@ -1245,6 +1245,19 @@ wl_global_get_user_data(const struct wl_global *global) return global->data; } +/** Set the global's user data + * + * \param global The global object + * \param data The user data pointer + * + * \since 1.17.90 + */ +WL_EXPORT void +wl_global_set_user_data(struct wl_global *global, void *data) +{ + global->data = data; +} + /** Get the current serial number * * \param display The display object -- 2.7.4