diff options
author | Bryce Harrington <bryce@osg.samsung.com> | 2015-09-23 17:30:43 -0700 |
---|---|---|
committer | Bryce Harrington <bryce@bryceharrington.org> | 2016-02-03 19:05:12 -0800 |
commit | 22b1f93432c775b6ed077c15a19e9e734a2806a5 (patch) | |
tree | 3615b2f9ef1cc3ec0adf5eb6f9de0da9a5b88fd7 /desktop-shell | |
parent | 90c2789e8d83a5b090cf4b91a6770a93f08028a0 (diff) |
shell: Check more thoroughly for undefined surface resource
The surface can have an undefined resource in certain situations (such
as with xwayland). So, since NULL is a valid state for this parameter,
and since the wl_resource_*, etc. calls require their parameters to be
non-NULL, make a practice of always checking the surface resource before
making wayland calls.
update v2:
* Fix some c/p errors for pointer names
* Drop null ptr check in add_popup_grab; probably redundant now
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Diffstat (limited to 'desktop-shell')
-rw-r--r-- | desktop-shell/shell.c | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index 5ae83efd..991effe5 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -2098,7 +2098,7 @@ xdg_ping_timeout_handler(void *data) continue; shsurf = get_shell_surface(pointer->focus->surface); - if (shsurf && + if (shsurf && shsurf->resource && wl_resource_get_client(shsurf->resource) == sc->client) set_busy_cursor(shsurf, pointer); } @@ -2133,7 +2133,8 @@ handle_xdg_ping(struct shell_surface *shsurf, uint32_t serial) if (shell_surface_is_xdg_surface(shsurf) || shell_surface_is_xdg_popup(shsurf)) xdg_shell_send_ping(sc->resource, serial); - else if (shell_surface_is_wl_shell_surface(shsurf)) + else if (shell_surface_is_wl_shell_surface(shsurf) + && shsurf->resource) wl_shell_surface_send_ping(shsurf->resource, serial); } @@ -3342,7 +3343,9 @@ static const struct weston_touch_grab_interface touch_popup_grab_interface = { static void shell_surface_send_popup_done(struct shell_surface *shsurf) { - if (shell_surface_is_wl_shell_surface(shsurf)) + if (shsurf->resource == NULL) + return; + else if (shell_surface_is_wl_shell_surface(shsurf)) wl_shell_surface_send_popup_done(shsurf->resource); else if (shell_surface_is_xdg_popup(shsurf)) xdg_popup_send_popup_done(shsurf->resource); @@ -3589,7 +3592,8 @@ shell_destroy_shell_surface(struct wl_resource *resource) if (!wl_list_empty(&shsurf->popup.grab_link)) remove_popup_grab(shsurf); - wl_list_remove(wl_resource_get_link(shsurf->resource)); + if (shsurf->resource) + wl_list_remove(wl_resource_get_link(shsurf->resource)); shsurf->resource = NULL; } @@ -3767,6 +3771,10 @@ shell_get_shell_surface(struct wl_client *client, shsurf->resource = wl_resource_create(client, &wl_shell_surface_interface, 1, id); + if (!shsurf->resource) { + wl_resource_post_no_memory(surface_resource); + return; + } wl_resource_set_implementation(shsurf->resource, &shell_surface_implementation, shsurf, shell_destroy_shell_surface); @@ -4115,6 +4123,10 @@ xdg_get_xdg_surface(struct wl_client *client, shsurf->resource = wl_resource_create(client, &xdg_surface_interface, 1, id); + if (!shsurf->resource) { + wl_resource_post_no_memory(surface_resource); + return; + } wl_resource_set_implementation(shsurf->resource, &xdg_surface_implementation, shsurf, shell_destroy_shell_surface); @@ -4246,6 +4258,10 @@ xdg_get_xdg_popup(struct wl_client *client, shsurf->resource = wl_resource_create(client, &xdg_popup_interface, 1, id); + if (!shsurf->resource) { + wl_resource_post_no_memory(surface_resource); + return; + } wl_resource_set_implementation(shsurf->resource, &xdg_popup_implementation, shsurf, shell_destroy_shell_surface); @@ -4266,9 +4282,10 @@ xdg_pong(struct wl_client *client, static bool shell_surface_is_xdg_popup(struct shell_surface *shsurf) { - return wl_resource_instance_of(shsurf->resource, - &xdg_popup_interface, - &xdg_popup_implementation); + return (shsurf->resource && + wl_resource_instance_of(shsurf->resource, + &xdg_popup_interface, + &xdg_popup_implementation)); } static const struct xdg_shell_interface xdg_implementation = { |