[glib] Fix a memory leak in g_ptr_array_remove_index_fast



commit 5fffa39b6ae8f8faf1036fbf07de02ffe84ef099
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jun 20 00:09:00 2010 -0400

    Fix a memory leak in g_ptr_array_remove_index_fast
    
    We need to call the element_free_func even if we remove the
    last element. Bug #618866.

 glib/garray.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)
---
diff --git a/glib/garray.c b/glib/garray.c
index a2bca94..b1e3baa 100644
--- a/glib/garray.c
+++ b/glib/garray.c
@@ -1075,13 +1075,12 @@ g_ptr_array_remove_index_fast (GPtrArray *farray,
   g_return_val_if_fail (index_ < array->len, NULL);
 
   result = array->pdata[index_];
-  
+
+  if (array->element_free_func != NULL)
+    array->element_free_func (array->pdata[index_]);
+
   if (index_ != array->len - 1)
-    {
-      if (array->element_free_func != NULL)
-        array->element_free_func (array->pdata[index_]);
-      array->pdata[index_] = array->pdata[array->len - 1];
-    }
+    array->pdata[index_] = array->pdata[array->len - 1];
 
   array->len -= 1;
 



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