[gimp] libgimp: do not return a possibly invalid pointer.



commit 345d148e217ed051118cc5d915fe2b2adfbefff1
Author: Jehan <jehan girinstud io>
Date:   Tue Oct 12 18:45:50 2021 +0200

    libgimp: do not return a possibly invalid pointer.
    
    Fixes the patch from !470 which is mostly right, except that
    g_param_spec_sink() may possibly lead to finalizing the GParamSpec
    (typically if it was a just-created floating spec). We don't want to
    return pointer to freed data. Let's return NULL instead.
    
    Also looking closer at the memory handling here, it looks the right
    annotation for @pspec is (transfer floating). Basically we are sinking a
    floating object into a full object and taking ownership of this sunk
    object. But if the object was already sunk, we are reffing it and
    keeping this additional reference, not the passed argument's. Hopefully
    it's right since the annotation and handling of floating object with
    GObject Introspection seems very unclear to me (even in core GObject
    code, I see what looks like contradictory annotations).

 libgimp/gimpprocedure.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
---
diff --git a/libgimp/gimpprocedure.c b/libgimp/gimpprocedure.c
index 81ec0c057d..af6aacc70d 100644
--- a/libgimp/gimpprocedure.c
+++ b/libgimp/gimpprocedure.c
@@ -1202,14 +1202,17 @@ gimp_procedure_get_date (GimpProcedure *procedure)
 /**
  * gimp_procedure_add_argument:
  * @procedure: the #GimpProcedure.
- * @pspec:     (transfer full): the argument specification.
+ * @pspec:     (transfer floating): the argument specification.
  *
  * Add a new argument to @procedure according to @pspec specifications.
  * The arguments will be ordered according to the call order to
  * gimp_procedure_add_argument() and
  * gimp_procedure_add_argument_from_property().
  *
- * Returns: (transfer none): the same @pspec.
+ * If @pspec is floating, ownership will be taken over by @procedure,
+ * allowing to pass directly g*_param_spec_*() calls as arguments.
+ *
+ * Returns: (transfer none): the same @pspec or %NULL in case of error.
  *
  * Since: 3.0
  **/
@@ -1227,7 +1230,7 @@ gimp_procedure_add_argument (GimpProcedure *procedure,
                  pspec->name,
                  gimp_procedure_get_name (procedure));
       g_param_spec_sink (pspec);
-      return pspec;
+      return NULL;
     }
 
   if (gimp_procedure_find_aux_argument (procedure, pspec->name))
@@ -1237,7 +1240,7 @@ gimp_procedure_add_argument (GimpProcedure *procedure,
                  pspec->name,
                  gimp_procedure_get_name (procedure));
       g_param_spec_sink (pspec);
-      return pspec;
+      return NULL;
     }
 
   procedure->priv->args = g_renew (GParamSpec *, procedure->priv->args,


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