[glib: 15/19] gvariant: Fix memory leak on a TYPE_CHECK failure




commit 05dffc1a7f562e9c8c6c21b67f99204f7a7b4e27
Author: Egor Bychin <e bychin drweb com>
Date:   Mon Oct 11 14:20:26 2021 +0300

    gvariant: Fix memory leak on a TYPE_CHECK failure

 glib/gvariant.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
---
diff --git a/glib/gvariant.c b/glib/gvariant.c
index a9bb99c64..4a9704c19 100644
--- a/glib/gvariant.c
+++ b/glib/gvariant.c
@@ -800,7 +800,13 @@ g_variant_new_array (const GVariantType *child_type,
 
   for (i = 0; i < n_children; i++)
     {
-      TYPE_CHECK (children[i], child_type, NULL);
+      if G_UNLIKELY (!g_variant_is_of_type (children[i], child_type))
+        {
+          while (i != 0)
+            g_variant_unref (my_children[--i]);
+          g_free (my_children);
+         g_return_val_if_fail (g_variant_is_of_type (children[i], child_type), NULL);
+        }
       my_children[i] = g_variant_ref_sink (children[i]);
       trusted &= g_variant_is_trusted (children[i]);
     }


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