compositor: Check wl_resource_create() return value

This fixes a number of call-sites to properly check for NULL and return
the no memory event when allocation fail.
diff --git a/src/compositor.c b/src/compositor.c
index e9ba0fd..e94b495 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1492,9 +1492,14 @@
 		return;
 	}
 
-	cb->resource = wl_resource_create(client,
-						      &wl_callback_interface,
-						      1, callback);
+	cb->resource = wl_resource_create(client, &wl_callback_interface, 1,
+					  callback);
+	if (cb->resource == NULL) {
+		free(cb);
+		wl_resource_post_no_memory(resource);
+		return;
+	}
+
 	wl_resource_set_implementation(cb->resource, NULL, cb,
 				       destroy_frame_callback);
 
@@ -1696,6 +1701,11 @@
 	surface->resource =
 		wl_resource_create(client, &wl_surface_interface,
 				   wl_resource_get_version(resource), id);
+	if (surface->resource == NULL) {
+		weston_surface_destroy(surface);
+		wl_resource_post_no_memory(resource);
+		return;
+	}
 	wl_resource_set_implementation(surface->resource, &surface_interface,
 				       surface, destroy_surface);
 }
@@ -1759,6 +1769,11 @@
 
 	region->resource =
 		wl_resource_create(client, &wl_region_interface, 1, id);
+	if (region->resource == NULL) {
+		free(region);
+		wl_resource_post_no_memory(resource);
+		return;
+	}
 	wl_resource_set_implementation(region->resource, &region_interface,
 				       region, destroy_region);
 }
@@ -2419,10 +2434,12 @@
 
 	resource =
 		wl_resource_create(client, &wl_subcompositor_interface, 1, id);
-	if (resource)
-		wl_resource_set_implementation(resource,
-					       &subcompositor_interface, 
-					       compositor, NULL);
+	if (resource == NULL) {
+		wl_client_post_no_memory(client);
+		return;
+	}
+	wl_resource_set_implementation(resource, &subcompositor_interface,
+				       compositor, NULL);
 }
 
 static void
@@ -2542,6 +2559,10 @@
 
 	resource = wl_resource_create(client, &wl_output_interface,
 				      MIN(version, 2), id);
+	if (resource == NULL) {
+		wl_client_post_no_memory(client);
+		return;
+	}
 
 	wl_list_insert(&output->resource_list, wl_resource_get_link(resource));
 	wl_resource_set_implementation(resource, NULL, data, unbind_resource);
@@ -2813,9 +2834,13 @@
 
 	resource = wl_resource_create(client, &wl_compositor_interface,
 				      MIN(version, 3), id);
-	if (resource)
-		wl_resource_set_implementation(resource, &compositor_interface,
-					       compositor, NULL);
+	if (resource == NULL) {
+		wl_client_post_no_memory(client);
+		return;
+	}
+
+	wl_resource_set_implementation(resource, &compositor_interface,
+				       compositor, NULL);
 }
 
 static void
diff --git a/src/data-device.c b/src/data-device.c
index d05b538..a76ae16 100644
--- a/src/data-device.c
+++ b/src/data-device.c
@@ -577,8 +577,13 @@
 
 	resource = wl_resource_create(client,
 				      &wl_data_device_interface, 1, id);
+	if (resource == NULL) {
+		wl_resource_post_no_memory(manager_resource);
+		return;
+	}
 
-	wl_list_insert(&seat->drag_resource_list, wl_resource_get_link(resource));
+	wl_list_insert(&seat->drag_resource_list,
+		       wl_resource_get_link(resource));
 	wl_resource_set_implementation(resource, &data_device_interface,
 				       seat, unbind_data_device);
 }
@@ -597,9 +602,13 @@
 	resource =
 		wl_resource_create(client,
 				   &wl_data_device_manager_interface, 1, id);
-	if (resource)
-		wl_resource_set_implementation(resource, &manager_interface,
-					       NULL, NULL);
+	if (resource == NULL) {
+		wl_client_post_no_memory(client);
+		return;
+	}
+
+	wl_resource_set_implementation(resource, &manager_interface,
+				       NULL, NULL);
 }
 
 WL_EXPORT void
diff --git a/src/input.c b/src/input.c
index 704ec0d..7dc6b68 100644
--- a/src/input.c
+++ b/src/input.c
@@ -1177,6 +1177,11 @@
 
         cr = wl_resource_create(client, &wl_pointer_interface,
 				wl_resource_get_version(resource), id);
+	if (cr == NULL) {
+		wl_client_post_no_memory(client);
+		return;
+	}
+
 	wl_list_insert(&seat->pointer->resource_list, wl_resource_get_link(cr));
 	wl_resource_set_implementation(cr, &pointer_interface, seat->pointer,
 				       unbind_resource);
@@ -1211,6 +1216,11 @@
 
         cr = wl_resource_create(client, &wl_keyboard_interface,
 				wl_resource_get_version(resource), id);
+	if (cr == NULL) {
+		wl_client_post_no_memory(client);
+		return;
+	}
+
 	wl_list_insert(&seat->keyboard->resource_list, wl_resource_get_link(cr));
 	wl_resource_set_implementation(cr, NULL, seat, unbind_resource);
 
@@ -1246,6 +1256,11 @@
 
         cr = wl_resource_create(client, &wl_touch_interface,
 				wl_resource_get_version(resource), id);
+	if (cr == NULL) {
+		wl_client_post_no_memory(client);
+		return;
+	}
+
 	wl_list_insert(&seat->touch->resource_list, wl_resource_get_link(cr));
 	wl_resource_set_implementation(cr, NULL, seat, unbind_resource);
 }