Skip to content

Commit

Permalink
Only remove weak pointers that are set.
Browse files Browse the repository at this point in the history
If the pointer has already been removed this generates a runtime warning.
  • Loading branch information
robert-ancell committed Jan 12, 2021
1 parent affaca3 commit 5fd25a9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
17 changes: 11 additions & 6 deletions shell/platform/linux/fl_key_event_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ G_DEFINE_TYPE(FlKeyEventResponseData, fl_key_event_response_data, G_TYPE_OBJECT)
static void fl_key_event_response_data_dispose(GObject* object) {
g_return_if_fail(FL_IS_KEY_EVENT_RESPONSE_DATA(object));
FlKeyEventResponseData* self = FL_KEY_EVENT_RESPONSE_DATA(object);
// Don't need to weak pointer anymore.
g_object_remove_weak_pointer(G_OBJECT(self->plugin),
reinterpret_cast<gpointer*>(&(self->plugin)));
if (self->plugin != nullptr) {
g_object_remove_weak_pointer(G_OBJECT(self->plugin),
reinterpret_cast<gpointer*>(&(self->plugin)));
self->plugin = nullptr;
}
}

// Class initialization method for FlKeyEventResponseData private class.
Expand Down Expand Up @@ -267,9 +269,12 @@ static void fl_key_event_plugin_dispose(GObject* object) {
FlKeyEventPlugin* self = FL_KEY_EVENT_PLUGIN(object);

g_clear_object(&self->channel);
g_object_remove_weak_pointer(
G_OBJECT(self->text_input_plugin),
reinterpret_cast<gpointer*>(&(self->text_input_plugin)));
if (self->text_input_plugin != nullptr) {
g_object_remove_weak_pointer(
G_OBJECT(self->text_input_plugin),
reinterpret_cast<gpointer*>(&(self->text_input_plugin)));
self->text_input_plugin = nullptr;
}
g_ptr_array_free(self->pending_events, TRUE);

G_OBJECT_CLASS(fl_key_event_plugin_parent_class)->dispose(object);
Expand Down
9 changes: 5 additions & 4 deletions shell/platform/linux/fl_mouse_cursor_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,11 @@ static void fl_mouse_cursor_plugin_dispose(GObject* object) {
FlMouseCursorPlugin* self = FL_MOUSE_CURSOR_PLUGIN(object);

g_clear_object(&self->channel);
g_object_remove_weak_pointer(G_OBJECT(self->view),
reinterpret_cast<gpointer*>(&(self->view)));
self->view = nullptr;

if (self->view != nullptr) {
g_object_remove_weak_pointer(G_OBJECT(self->view),
reinterpret_cast<gpointer*>(&(self->view)));
self->view = nullptr;
}
g_clear_pointer(&self->system_cursor_table, g_hash_table_unref);

G_OBJECT_CLASS(fl_mouse_cursor_plugin_parent_class)->dispose(object);
Expand Down
8 changes: 5 additions & 3 deletions shell/platform/linux/fl_plugin_registrar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ G_DEFINE_TYPE(FlPluginRegistrar, fl_plugin_registrar, G_TYPE_OBJECT)
static void fl_plugin_registrar_dispose(GObject* object) {
FlPluginRegistrar* self = FL_PLUGIN_REGISTRAR(object);

g_object_remove_weak_pointer(G_OBJECT(self->view),
reinterpret_cast<gpointer*>(&(self->view)));
self->view = nullptr;
if (self->view != nullptr) {
g_object_remove_weak_pointer(G_OBJECT(self->view),
reinterpret_cast<gpointer*>(&(self->view)));
self->view = nullptr;
}
g_clear_object(&self->messenger);

G_OBJECT_CLASS(fl_plugin_registrar_parent_class)->dispose(object);
Expand Down

0 comments on commit 5fd25a9

Please sign in to comment.