aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2018-06-23 18:55:37 +0100
committeremersion <contact@emersion.fr>2018-06-30 22:18:04 +0100
commit9aaa9ba477f98f0eb827969f80bb845cfef2dd4b (patch)
tree2913c32a28f003c466dfd7bed741b9ce2210c458
parentc421700f3da6333652488e2951c2b0cbb8e35e51 (diff)
screencopy: make frame resource inert after copy
-rw-r--r--types/wlr_screencopy_v1.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/types/wlr_screencopy_v1.c b/types/wlr_screencopy_v1.c
index 027d4b51..c897e41e 100644
--- a/types/wlr_screencopy_v1.c
+++ b/types/wlr_screencopy_v1.c
@@ -17,6 +17,17 @@ static struct wlr_screencopy_frame_v1 *frame_from_resource(
return wl_resource_get_user_data(resource);
}
+static void frame_destroy(struct wlr_screencopy_frame_v1 *frame) {
+ if (frame == NULL) {
+ return;
+ }
+ wl_list_remove(&frame->link);
+ wl_list_remove(&frame->output_swap_buffers.link);
+ // Make the frame resource inert
+ wl_resource_set_user_data(frame->resource, NULL);
+ free(frame);
+}
+
static void frame_handle_output_swap_buffers(struct wl_listener *listener,
void *_data) {
struct wlr_screencopy_frame_v1 *frame =
@@ -48,6 +59,7 @@ static void frame_handle_output_swap_buffers(struct wl_listener *listener,
if (!ok) {
zwlr_screencopy_frame_v1_send_failed(frame->resource);
+ frame_destroy(frame);
return;
}
@@ -58,13 +70,17 @@ static void frame_handle_output_swap_buffers(struct wl_listener *listener,
zwlr_screencopy_frame_v1_send_ready(frame->resource,
tv_sec_hi, tv_sec_lo, event->when->tv_nsec);
- // TODO: make frame resource inert
+ frame_destroy(frame);
}
static void frame_handle_copy(struct wl_client *client,
struct wl_resource *frame_resource,
struct wl_resource *buffer_resource) {
struct wlr_screencopy_frame_v1 *frame = frame_from_resource(frame_resource);
+ if (frame == NULL) {
+ return;
+ }
+
struct wlr_output *output = frame->output;
struct wl_shm_buffer *buffer = wl_shm_buffer_get(buffer_resource);
@@ -119,9 +135,7 @@ static const struct zwlr_screencopy_frame_v1_interface frame_impl = {
static void frame_handle_resource_destroy(struct wl_resource *frame_resource) {
struct wlr_screencopy_frame_v1 *frame = frame_from_resource(frame_resource);
- wl_list_remove(&frame->link);
- wl_list_remove(&frame->output_swap_buffers.link);
- free(frame);
+ frame_destroy(frame);
}