Some memory leaks as pointed out by Valgrind

Chris Shoemaker c.shoemaker at cox.net
Sun May 6 18:31:43 EDT 2007


On Sun, May 06, 2007 at 11:26:52PM +0200, Christian Stimming wrote:
> Here is some output of valgrind. This is with "gnucash --nofile" and directly 
> terminating the program again. I'm trying to get some actual numbers for  
> http://bugzilla.gnome.org/show_bug.cgi?id=431324 , but as one startup of 
> gnucash with valgrind takes approx. 10 minutes :-) , I'm progressing quite 
> slowly. But some issues are there already:
> 
> ==5392== 44,394 bytes in 1,676 blocks are definitely lost in loss record 251 
> of 261
> ==5392==    at 0x4023515: malloc (vg_replace_malloc.c:149)
> ==5392==    by 0x559B265: g_malloc (in /opt/gnome/lib/libglib-2.0.so.0.1200.4)
> ==5392==    by 0x55AEA98: g_strdup (in /opt/gnome/lib/libglib-2.0.so.0.1200.4)
> ==5392==    by 0x557D5E3: g_cache_insert 
> (in /opt/gnome/lib/libglib-2.0.so.0.1200.4)
> ==5392==    by 0x4055C20: qof_util_string_cache_insert (qofutil.c:296)
> ==5392==    by 0x4048EBF: qof_collection_new (qofid.c:101)
> ==5392==    by 0x404EDFB: qof_book_get_collection (qofbook.c:302)
> ==5392==    by 0x404ACC7: qof_instance_init_data (qofinstance.c:287)
> ==5392==    by 0x408EB74: book_sxes_setup (SX-book.c:251)
> ==5392==    by 0x40514E0: qof_object_book_begin (qofobject.c:66)
> ==5392==    by 0x404F3F6: qof_book_new (qofbook.c:88)
> ==5392==    by 0x40588E6: qof_session_new (qofsession.c:197)
> 
> Seems like the keys in the g_cache should be explicitly free'd after use, but 
> currently they aren't.

This leak is at least documented in book_sxes_setup().

> ==5392== 3,428 bytes in 185 blocks are definitely lost in loss record 213 of 
> 261
> ==5392==    at 0x4023515: malloc (vg_replace_malloc.c:149)
> ==5392==    by 0x56B5ADF: strdup (in /lib/libc-2.5.so)
> ==5392==    by 0x42E23C1: gnc_gettext_helper (gnc-gettext-util.c:35)
> ==5392==    by 0x42DBB1D: _wrap_gnc_gettext_helper (swig-app-utils.c:1287)
> ==5392==    by 0x5417D9E: (within /usr/lib/libguile.so.17.0.1)
> ==5392==    by 0x5418F42: (within /usr/lib/libguile.so.17.0.1)
> ==5392==    by 0x5418C64: (within /usr/lib/libguile.so.17.0.1)
> ==5392==    by 0x5419E2F: (within /usr/lib/libguile.so.17.0.1)
> ==5392==    by 0x5418CC0: (within /usr/lib/libguile.so.17.0.1)
> ==5392==    by 0x541D789: scm_primitive_eval_x 
> (in /usr/lib/libguile.so.17.0.1)
> ==5392==    by 0x5472BB7: (within /usr/lib/libguile.so.17.0.1)
> ==5392==    by 0x541F4CD: scm_c_with_fluid (in /usr/lib/libguile.so.17.0.1)
> 
> Our gnc_gettext_helper returns a newly allocated string, but swig's generated 
> _wrap_gnc_gettext_helper function doesn't free this string. Who has to fix 
> this, we or swig?

This is certainly our responsibility, and should be easy to fix.
I'll see if I can look into this this evening.

-chris


More information about the gnucash-devel mailing list