[glib: 1/8] gptrarray: Set free func on copied array in g_ptr_array_copy()



commit 1ac8d50331d3b32390ac8a8e35e1ad860a7b4c3e
Author: Philip Withnall <withnall endlessm com>
Date:   Tue Jul 16 10:15:09 2019 +0100

    gptrarray: Set free func on copied array in g_ptr_array_copy()
    
    Otherwise its elements (which have just all been copied) will leak.
    
    Spotted by Xavier Claessens in
    https://gitlab.gnome.org/GNOME/glib/merge_requests/918#note_555867.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 glib/garray.c | 5 +++++
 1 file changed, 5 insertions(+)
---
diff --git a/glib/garray.c b/glib/garray.c
index 29be5f7ef..075cb8d73 100644
--- a/glib/garray.c
+++ b/glib/garray.c
@@ -1020,6 +1020,9 @@ g_ptr_array_new (void)
  * If @func is %NULL, then only the pointers (and not what they are
  * pointing to) are copied to the new #GPtrArray.
  *
+ * The copy of @array will have the same #GDestroyNotify for its elements as
+ * @array.
+ *
  * Returns: (transfer full): a deep copy of the initial #GPtrArray.
  *
  * Since: 2.62
@@ -1035,6 +1038,8 @@ g_ptr_array_copy (GPtrArray *array,
   g_return_val_if_fail (array != NULL, NULL);
 
   new_array = g_ptr_array_sized_new (array->len);
+  g_ptr_array_set_free_func (new_array, ((GRealPtrArray *) array)->element_free_func);
+
   if (func != NULL)
     {
       for (i = 0; i < array->len; i++)


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