From 83869120bba2aa745a1b23fb415ab0eddd6f9327 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Mon, 28 Oct 2013 14:59:26 -0700 Subject: [PATCH] GSimpleAction: don't allow changing state type g_object_set() allowed us to bypass the usual checks that the state doesn't change type and also leaked. Fix that up by turning the state into a construct property (so that it always gets set once during construction, even if only to NULL) and then route the further sets through the C API so that they are subject to the same checks. https://bugzilla.gnome.org/show_bug.cgi?id=696424 --- gio/gsimpleaction.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/gio/gsimpleaction.c b/gio/gsimpleaction.c index 49188ad..c694808 100644 --- a/gio/gsimpleaction.c +++ b/gio/gsimpleaction.c @@ -45,6 +45,7 @@ struct _GSimpleAction GVariantType *parameter_type; gboolean enabled; GVariant *state; + gboolean state_set_already; }; typedef GObjectClass GSimpleActionClass; @@ -232,7 +233,20 @@ g_simple_action_set_property (GObject *object, break; case PROP_STATE: - action->state = g_value_dup_variant (value); + /* The first time we see this (during construct) we should just + * take the state as it was handed to us. + * + * After that, we should make sure we go through the same checks + * as the C API. + */ + if (!action->state_set_already) + { + action->state = g_value_dup_variant (value); + action->state_set_already = TRUE; + } + else + g_simple_action_set_state (action, g_value_get_variant (value)); + break; default: @@ -470,7 +484,7 @@ g_simple_action_class_init (GSimpleActionClass *class) P_("The state the action is in"), G_VARIANT_TYPE_ANY, NULL, - G_PARAM_READWRITE | + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); } -- 2.7.4