[glib: 1/2] gparam: fix memory leak in g_param_value_defaults()



commit 3a9bdcf70467e6d35123158250143b50fcf6f027
Author: Thomas Haller <thaller redhat com>
Date:   Fri Nov 8 21:23:01 2019 +0100

    gparam: fix memory leak in g_param_value_defaults()
    
    We cannot  just call
    
        G_PARAM_SPEC_GET_CLASS (pspec)->value_set_default (pspec, &dflt_value);
    
    without initializing the GValue first. It would call
    param_string_set_default(), which would set the pointer value
    to a cloned string (which later never gets released, because
    the GValue is not known to hold a string).
    
    Fixes: 6ad799ac677ae241da8b32ecf33b5cc9dc1d30bc

 gobject/gparam.c | 1 +
 1 file changed, 1 insertion(+)
---
diff --git a/gobject/gparam.c b/gobject/gparam.c
index 1158cddb7..77b00aba6 100644
--- a/gobject/gparam.c
+++ b/gobject/gparam.c
@@ -640,6 +640,7 @@ g_param_value_defaults (GParamSpec   *pspec,
   g_return_val_if_fail (G_IS_VALUE (value), FALSE);
   g_return_val_if_fail (PSPEC_APPLIES_TO_VALUE (pspec, value), FALSE);
 
+  g_value_init (&dflt_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
   G_PARAM_SPEC_GET_CLASS (pspec)->value_set_default (pspec, &dflt_value);
   defaults = G_PARAM_SPEC_GET_CLASS (pspec)->values_cmp (pspec, value, &dflt_value) == 0;
   g_value_unset (&dflt_value);


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