Memory leaks in using g_ptr_array_free() of GLib?



Hello,
First of all, sorry if this is not the adecuate list to ask about
GLib, but I haven't found the list about GLib.
I'm newbie with GLib and I have some problems about memory leaks. I'm
testing the simple code:

#include<glib.h>
int main(){
    GPtrArray* dataArray=g_ptr_array_new();
    g_ptr_array_free(dataArray,TRUE);
    return 0;
}

I only initialize and free one GPtrArray object.
if I compile it and run with valgrind (http://valgrind.org/) I obtain:

gcc -g -Wall -Wextra -I/usr/include/glib-2.0
-I/usr/lib/glib-2.0/include  memptr.c -o memptr -lgts
valgrind --leak-check=full ./memptr

==30774== HEAP SUMMARY:
==30774==     in use at exit: 5,052 bytes in 10 blocks
==30774==   total heap usage: 10 allocs, 0 frees, 5,052 bytes allocated
==30774==
==30774== 1,240 bytes in 5 blocks are possibly lost in loss record 5 of 6
==30774==    at 0x4023E5E: memalign (vg_replace_malloc.c:532)
==30774==    by 0x4023EBB: posix_memalign (vg_replace_malloc.c:660)
==30774==    by 0x422F431: ??? (in /lib/libglib-2.0.so.0.2400.0)
==30774==    by 0x422FC92: g_slice_alloc (in /lib/libglib-2.0.so.0.2400.0)
==30774==    by 0x41EAADA: g_ptr_array_sized_new (in
/lib/libglib-2.0.so.0.2400.0)
==30774==    by 0x41EAB31: g_ptr_array_new (in /lib/libglib-2.0.so.0.2400.0)
==30774==    by 0x8048511: main (memgts.c:5)
==30774==
==30774== LEAK SUMMARY:
==30774==    definitely lost: 0 bytes in 0 blocks
==30774==    indirectly lost: 0 bytes in 0 blocks
==30774==      possibly lost: 1,240 bytes in 5 blocks
==30774==    still reachable: 3,812 bytes in 5 blocks
==30774==         suppressed: 0 bytes in 0 blocks
==30774== Reachable blocks (those to which a pointer was found) are not shown.
==30774== To see them, rerun with: --leak-check=full --show-reachable=yes
==30774==
==30774== For counts of detected and suppressed errors, rerun with: -v
==30774== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 19 from 6)

Valgrind says that some memory were lost (possibly lost and still
reachable). Is this behaviour known? Is it a bug? What is the correct
way fot free GPtrArray?

-- 
*****************************************
José Luis García Pallero
jgpallero gmail com
(o<
/ / \
V_/_
Use Debian GNU/Linux and enjoy!
*****************************************


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