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>
This commit is contained in:
Philip Withnall 2019-07-16 10:15:09 +01:00
parent d076c4c688
commit 1ac8d50331

View File

@ -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++)