diff --git a/gio/gpropertyaction.c b/gio/gpropertyaction.c index 8df765e98..52eae84e5 100644 --- a/gio/gpropertyaction.c +++ b/gio/gpropertyaction.c @@ -313,6 +313,15 @@ g_property_action_set_property_name (GPropertyAction *paction, GParamSpec *pspec; gchar *detailed; + /* In case somebody is constructing GPropertyAction without passing + * a property name + */ + if (G_UNLIKELY (property_name == NULL || property_name[0] == '\0')) + { + g_critical ("Attempted to use an empty property name for GPropertyAction"); + return; + } + pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (paction->object), property_name); if (pspec == NULL) @@ -407,13 +416,25 @@ g_property_action_get_property (GObject *object, } } +static void +g_property_action_dispose (GObject *object) +{ + GPropertyAction *paction = G_PROPERTY_ACTION (object); + + if (paction->object != NULL) + { + g_signal_handlers_disconnect_by_func (paction->object, g_property_action_notify, paction); + g_clear_object (&paction->object); + } + + G_OBJECT_CLASS (g_property_action_parent_class)->dispose (object); +} + static void g_property_action_finalize (GObject *object) { GPropertyAction *paction = G_PROPERTY_ACTION (object); - g_signal_handlers_disconnect_by_func (paction->object, g_property_action_notify, paction); - g_object_unref (paction->object); g_free (paction->name); G_OBJECT_CLASS (g_property_action_parent_class) @@ -445,6 +466,7 @@ g_property_action_class_init (GPropertyActionClass *class) object_class->set_property = g_property_action_set_property; object_class->get_property = g_property_action_get_property; + object_class->dispose = g_property_action_dispose; object_class->finalize = g_property_action_finalize; /** diff --git a/gio/tests/actions.c b/gio/tests/actions.c index e3868532b..a24c52c5e 100644 --- a/gio/tests/actions.c +++ b/gio/tests/actions.c @@ -1421,6 +1421,20 @@ test_property_actions (void) g_object_unref (group); } +static void +test_property_actions_no_properties (void) +{ + GPropertyAction *action; + + g_test_expect_message ("GLib-GIO", G_LOG_LEVEL_CRITICAL, "*Attempted to use an empty property name for GPropertyAction*"); + action = (GPropertyAction*) g_object_new_with_properties (G_TYPE_PROPERTY_ACTION, 0, NULL, NULL); + + g_test_assert_expected_messages (); + g_assert_true (G_IS_PROPERTY_ACTION (action)); + + g_object_unref (action); +} + int main (int argc, char **argv) { @@ -1437,6 +1451,7 @@ main (int argc, char **argv) g_test_add_func ("/actions/dbus/threaded", test_dbus_threaded); g_test_add_func ("/actions/dbus/bug679509", test_bug679509); g_test_add_func ("/actions/property", test_property_actions); + g_test_add_func ("/actions/no-properties", test_property_actions_no_properties); return g_test_run (); }