diff --git a/include/wlr/types/wlr_data_device.h b/include/wlr/types/wlr_data_device.h index fa5a7834..4893bbf4 100644 --- a/include/wlr/types/wlr_data_device.h +++ b/include/wlr/types/wlr_data_device.h @@ -126,4 +126,6 @@ void wlr_seat_set_selection(struct wlr_seat *seat, void wlr_data_source_init(struct wlr_data_source *source); +void wlr_data_source_finish(struct wlr_data_source *source); + #endif diff --git a/include/wlr/types/wlr_primary_selection.h b/include/wlr/types/wlr_primary_selection.h index 94309b57..b4eceb78 100644 --- a/include/wlr/types/wlr_primary_selection.h +++ b/include/wlr/types/wlr_primary_selection.h @@ -52,5 +52,7 @@ void wlr_seat_set_primary_selection(struct wlr_seat *seat, void wlr_primary_selection_source_init( struct wlr_primary_selection_source *source); +void wlr_primary_selection_source_finish( + struct wlr_primary_selection_source *source); #endif diff --git a/types/wlr_data_device.c b/types/wlr_data_device.c index eb1b4e0f..51789047 100644 --- a/types/wlr_data_device.c +++ b/types/wlr_data_device.c @@ -856,16 +856,7 @@ void data_device_manager_get_data_device(struct wl_client *client, static void data_source_resource_destroy(struct wl_resource *resource) { struct wlr_data_source *source = wl_resource_get_user_data(resource); - char **p; - - wl_signal_emit(&source->events.destroy, source); - - wl_array_for_each(p, &source->mime_types) { - free(*p); - } - - wl_array_release(&source->mime_types); - + wlr_data_source_finish(source); free(source); } @@ -932,6 +923,20 @@ void wlr_data_source_init(struct wlr_data_source *source) { wl_signal_init(&source->events.destroy); } +void wlr_data_source_finish(struct wlr_data_source *source) { + if (source == NULL) { + return; + } + + wl_signal_emit(&source->events.destroy, source); + + char **p; + wl_array_for_each(p, &source->mime_types) { + free(*p); + } + wl_array_release(&source->mime_types); +} + static void data_device_manager_create_data_source(struct wl_client *client, struct wl_resource *resource, uint32_t id) { struct wlr_data_source *source = calloc(1, sizeof(struct wlr_data_source)); diff --git a/types/wlr_primary_selection.c b/types/wlr_primary_selection.c index 5af90121..8163d2e5 100644 --- a/types/wlr_primary_selection.c +++ b/types/wlr_primary_selection.c @@ -144,15 +144,7 @@ static const struct gtk_primary_selection_source_interface source_impl = { static void source_resource_handle_destroy(struct wl_resource *resource) { struct wlr_primary_selection_source *source = wl_resource_get_user_data(resource); - - wl_signal_emit(&source->events.destroy, source); - - char **p; - wl_array_for_each(p, &source->mime_types) { - free(*p); - } - wl_array_release(&source->mime_types); - + wlr_primary_selection_source_finish(source); free(source); } @@ -268,6 +260,21 @@ void wlr_primary_selection_source_init( wl_signal_init(&source->events.destroy); } +void wlr_primary_selection_source_finish( + struct wlr_primary_selection_source *source) { + if (source == NULL) { + return; + } + + wl_signal_emit(&source->events.destroy, source); + + char **p; + wl_array_for_each(p, &source->mime_types) { + free(*p); + } + wl_array_release(&source->mime_types); +} + static void device_manager_handle_create_source(struct wl_client *client, struct wl_resource *manager_resource, uint32_t id) { struct wlr_primary_selection_source *source = diff --git a/xwayland/selection.c b/xwayland/selection.c index be803599..e59bc4e6 100644 --- a/xwayland/selection.c +++ b/xwayland/selection.c @@ -508,6 +508,7 @@ static void data_source_send(struct wlr_data_source *base, static void data_source_cancel(struct wlr_data_source *base) { struct x11_data_source *source = (struct x11_data_source *)base; + wlr_data_source_finish(&source->base); wl_array_release(&source->mime_types_atoms); free(source); } @@ -533,6 +534,7 @@ static void primary_selection_source_cancel( struct wlr_primary_selection_source *base) { struct x11_primary_selection_source *source = (struct x11_primary_selection_source *)base; + wlr_primary_selection_source_finish(&source->base); wl_array_release(&source->mime_types_atoms); free(source); }