commit 98b8e8f522e65c86dd94e2e29b3ff5d12b106fbe
parent 8fdf857567cd592f313e45952d9a2917414fc8fd
Author: Michael Forney <mforney@mforney.org>
Date: Sat, 4 Jan 2020 14:37:52 -0800
Add missing error checks for resource creation
Diffstat:
11 files changed, 74 insertions(+), 22 deletions(-)
diff --git a/libswc/compositor.c b/libswc/compositor.c
@@ -793,6 +793,10 @@ bind_compositor(struct wl_client *client, void *data, uint32_t version, uint32_t
struct wl_resource *resource;
resource = wl_resource_create(client, &wl_compositor_interface, version, id);
+ if (!resource) {
+ wl_client_post_no_memory(client);
+ return;
+ }
wl_resource_set_implementation(resource, &compositor_impl, NULL, NULL);
}
diff --git a/libswc/drm.c b/libswc/drm.c
@@ -1,6 +1,6 @@
/* swc: drm.c
*
- * Copyright (c) 2013-2019 Michael Forney
+ * Copyright (c) 2013-2020 Michael Forney
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -240,6 +240,10 @@ bind_drm(struct wl_client *client, void *data, uint32_t version, uint32_t id)
struct wl_resource *resource;
resource = wl_resource_create(client, &wl_drm_interface, version, id);
+ if (!resource) {
+ wl_client_post_no_memory(client);
+ return;
+ }
wl_resource_set_implementation(resource, &drm_impl, NULL, NULL);
if (version >= 2)
diff --git a/libswc/keyboard.c b/libswc/keyboard.c
@@ -1,6 +1,6 @@
/* swc: libswc/keyboard.c
*
- * Copyright (c) 2013 Michael Forney
+ * Copyright (c) 2013-2020 Michael Forney
*
* Based in part upon input.c from weston, which is:
*
@@ -310,6 +310,8 @@ keyboard_bind(struct keyboard *keyboard, struct wl_client *client, uint32_t vers
struct wl_resource *client_resource;
client_resource = wl_resource_create(client, &wl_keyboard_interface, version, id);
+ if (!client_resource)
+ return NULL;
wl_resource_set_implementation(client_resource, &keyboard_impl, keyboard, &unbind);
/* Subtract one to remove terminating NULL character. */
diff --git a/libswc/panel_manager.c b/libswc/panel_manager.c
@@ -1,6 +1,6 @@
/* swc: libswc/panel_manager.c
*
- * Copyright (c) 2013-2019 Michael Forney
+ * Copyright (c) 2013-2020 Michael Forney
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -47,6 +47,10 @@ bind_panel_manager(struct wl_client *client, void *data, uint32_t version, uint3
struct wl_resource *resource;
resource = wl_resource_create(client, &swc_panel_manager_interface, version, id);
+ if (!resource) {
+ wl_client_post_no_memory(client);
+ return;
+ }
wl_resource_set_implementation(resource, &panel_manager_impl, NULL, NULL);
}
diff --git a/libswc/pointer.c b/libswc/pointer.c
@@ -1,6 +1,6 @@
/* swc: libswc/pointer.c
*
- * Copyright (c) 2013, 2014 Michael Forney
+ * Copyright (c) 2013-2020 Michael Forney
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -349,6 +349,8 @@ pointer_bind(struct pointer *pointer, struct wl_client *client, uint32_t version
struct wl_resource *client_resource;
client_resource = wl_resource_create(client, &wl_pointer_interface, version, id);
+ if (!client_resource)
+ return NULL;
wl_resource_set_implementation(client_resource, &pointer_impl, pointer, &unbind);
input_focus_add_resource(&pointer->focus, client_resource);
diff --git a/libswc/region.c b/libswc/region.c
@@ -42,13 +42,20 @@ region_new(struct wl_client *client, uint32_t version, uint32_t id)
struct region *region;
region = malloc(sizeof(*region));
-
if (!region)
- return NULL;
+ goto error0;
- pixman_region32_init(®ion->region);
region->resource = wl_resource_create(client, &wl_region_interface, version, id);
+ if (!region->resource)
+ goto error1;
+
+ pixman_region32_init(®ion->region);
wl_resource_set_implementation(region->resource, ®ion_impl, region, ®ion_destroy);
return region;
+
+error1:
+ free(region);
+error0:
+ return NULL;
}
diff --git a/libswc/seat.c b/libswc/seat.c
@@ -1,6 +1,6 @@
/* swc: libswc/seat.c
*
- * Copyright (c) 2013, 2014 Michael Forney
+ * Copyright (c) 2013-2020 Michael Forney
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -124,7 +124,8 @@ get_pointer(struct wl_client *client, struct wl_resource *resource, uint32_t id)
{
struct seat *seat = wl_resource_get_user_data(resource);
- pointer_bind(&seat->pointer, client, wl_resource_get_version(resource), id);
+ if (!pointer_bind(&seat->pointer, client, wl_resource_get_version(resource), id))
+ wl_resource_post_no_memory(resource);
}
static void
@@ -132,7 +133,8 @@ get_keyboard(struct wl_client *client, struct wl_resource *resource, uint32_t id
{
struct seat *seat = wl_resource_get_user_data(resource);
- keyboard_bind(seat->base.keyboard, client, wl_resource_get_version(resource), id);
+ if (!keyboard_bind(seat->base.keyboard, client, wl_resource_get_version(resource), id))
+ wl_resource_post_no_memory(resource);
}
static void
@@ -154,6 +156,10 @@ bind_seat(struct wl_client *client, void *data, uint32_t version, uint32_t id)
struct wl_resource *resource;
resource = wl_resource_create(client, &wl_seat_interface, version, id);
+ if (!resource) {
+ wl_client_post_no_memory(client);
+ return;
+ }
wl_resource_set_implementation(resource, &seat_impl, seat, &remove_resource);
wl_list_insert(&seat->resources, wl_resource_get_link(resource));
diff --git a/libswc/shell.c b/libswc/shell.c
@@ -1,6 +1,6 @@
/* swc: libswc/shell.c
*
- * Copyright (c) 2013-2019 Michael Forney
+ * Copyright (c) 2013-2020 Michael Forney
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -49,6 +49,10 @@ bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
struct wl_resource *resource;
resource = wl_resource_create(client, &wl_shell_interface, version, id);
+ if (!resource) {
+ wl_client_post_no_memory(client);
+ return;
+ }
wl_resource_set_implementation(resource, &shell_implementation, NULL, NULL);
}
diff --git a/libswc/shm.c b/libswc/shm.c
@@ -1,6 +1,6 @@
/* swc: libswc/shm.c
*
- * Copyright (c) 2013-2019 Michael Forney
+ * Copyright (c) 2013-2020 Michael Forney
*
* Based in part upon wayland-shm.c from wayland, which is:
*
@@ -200,6 +200,10 @@ bind_shm(struct wl_client *client, void *data, uint32_t version, uint32_t id)
struct wl_resource *resource;
resource = wl_resource_create(client, &wl_shm_interface, version, id);
+ if (!resource) {
+ wl_client_post_no_memory(client);
+ return;
+ }
wl_resource_set_implementation(resource, &shm_impl, shm, NULL);
wl_shm_send_format(resource, WL_SHM_FORMAT_XRGB8888);
diff --git a/libswc/subcompositor.c b/libswc/subcompositor.c
@@ -1,6 +1,6 @@
/* swc: libswc/subcompositor.c
*
- * Copyright (c) 2015-2019 Michael Forney
+ * Copyright (c) 2015-2020 Michael Forney
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -54,6 +54,10 @@ bind_subcompositor(struct wl_client *client, void *data, uint32_t version, uint3
struct wl_resource *resource;
resource = wl_resource_create(client, &wl_subcompositor_interface, version, id);
+ if (!resource) {
+ wl_client_post_no_memory(client);
+ return;
+ }
wl_resource_set_implementation(resource, &subcompositor_impl, NULL, NULL);
}
diff --git a/libswc/surface.c b/libswc/surface.c
@@ -1,6 +1,6 @@
/* swc: surface.c
*
- * Copyright (c) 2013 Michael Forney
+ * Copyright (c) 2013-2020 Michael Forney
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -171,8 +171,12 @@ frame(struct wl_client *client, struct wl_resource *resource, uint32_t id)
struct surface *surface = wl_resource_get_user_data(resource);
struct wl_resource *callback_resource;
- surface->pending.commit |= SURFACE_COMMIT_FRAME;
callback_resource = wl_resource_create(client, &wl_callback_interface, 1, id);
+ if (!callback_resource) {
+ wl_resource_post_no_memory(resource);
+ return;
+ }
+ surface->pending.commit |= SURFACE_COMMIT_FRAME;
wl_resource_set_implementation(callback_resource, NULL, NULL, &remove_resource);
wl_list_insert(surface->pending.state.frame_callbacks.prev, wl_resource_get_link(callback_resource));
}
@@ -310,7 +314,7 @@ surface_destroy(struct wl_resource *resource)
/**
* Construct a new surface, adding it to the given client as id.
*
- * The surface will be free'd automatically when it's resource is destroyed.
+ * The surface will be free'd automatically when its resource is destroyed.
*
* @return The newly allocated surface.
*/
@@ -319,8 +323,14 @@ surface_new(struct wl_client *client, uint32_t version, uint32_t id)
{
struct surface *surface;
- if (!(surface = malloc(sizeof(*surface))))
- return NULL;
+ surface = malloc(sizeof(*surface));
+ if (!surface)
+ goto error0;
+
+ surface->resource = wl_resource_create(client, &wl_surface_interface, version, id);
+ if (!surface->resource)
+ goto error1;
+ wl_resource_set_implementation(surface->resource, &surface_impl, surface, &surface_destroy);
/* Initialize the surface. */
surface->pending.commit = 0;
@@ -330,11 +340,12 @@ surface_new(struct wl_client *client, uint32_t version, uint32_t id)
state_initialize(&surface->state);
state_initialize(&surface->pending.state);
- /* Add the surface to the client. */
- surface->resource = wl_resource_create(client, &wl_surface_interface, version, id);
- wl_resource_set_implementation(surface->resource, &surface_impl, surface, &surface_destroy);
-
return surface;
+
+error1:
+ free(surface);
+error0:
+ return NULL;
}
void