[libadwaita/ebassi/toast-variant] Fix AdwToast's use of GVariant




commit df0f65341cd37fdf38123da875564511d4e89feb
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Mar 3 18:55:32 2022 +0000

    Fix AdwToast's use of GVariant
    
    The adw_toast_set_action_target_value() function only
    acquires a reference on the GVariant, but we use it
    internally with variants directly returned by a
    g_variant_new constructor, which returns a floating
    reference that must be sunk.
    
    Functions that take a GVariant should always call
    g_variant_ref_sink(), unless they are merely holding
    a reference and they are documented as requiring a
    non-floating GVariant.

 src/adw-toast.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
---
diff --git a/src/adw-toast.c b/src/adw-toast.c
index e05d940b..e0de2d93 100644
--- a/src/adw-toast.c
+++ b/src/adw-toast.c
@@ -590,6 +590,9 @@ adw_toast_get_action_target_value (AdwToast *self)
  *
  * Sets the parameter for action invocations.
  *
+ * If the @action_target variant has a floating reference this function
+ * will sink it.
+ *
  * Since: 1.0
  */
 void
@@ -606,7 +609,8 @@ adw_toast_set_action_target_value (AdwToast *self,
     return;
 
   g_clear_pointer (&self->action_target, g_variant_unref);
-  self->action_target = g_variant_ref (action_target);
+  if (action_target != NULL)
+    self->action_target = g_variant_ref_sink (action_target);
 
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ACTION_TARGET]);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]