GNOME Bugzilla – Bug 120258
Glib console warnings creates memory leak?
Last modified: 2004-12-22 21:47:04 UTC
When I use gmime for file-to-gmimemessage parsing, I get leaks. After having this discussed with the author of gmime, Jeffrey Stedfast, he pointed out that it looks like a glib leak. The leak happens probably when glib writes an error to the console. I dont code much with glib, so Im unfortunately unable to actually verify the leak without spending a lot of time on it. The sourcecode: int main(void) { g_type_init(); FILE *fd_cache = fopen("/tmp/mimedata", "r"); if (!fd_cache) return; GMimeStream *gstream = g_mime_stream_file_new(fd_cache); GMimeParser *gparser = g_mime_parser_new_with_stream(gstream); GMimeMessage *gmsg = g_mime_parser_construct_message(gparser); g_mime_stream_close(gstream); g_object_unref(gparser); g_object_unref(GMIME_OBJECT(gmsg)); g_mime_stream_unref(gstream); return 1; } Valgrind log: bash-2.05a$ /tmp/valgrind/bin/valgrind --alignment=8 --error-limit=no --num-callers=12 --leak-check=yes --show-reachable=yes ./t3 ==1774== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux. ==1774== Copyright (C) 2002-2003, and GNU GPL'd, by Julian Seward. ==1774== Using valgrind-20030725, a program supervision framework for x86-linux. ==1774== Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward. ==1774== Estimated CPU clock rate is 1133 MHz ==1774== For more details, rerun with: -v ==1774== (process:1774): gmime-CRITICAL **: file gmime-object.c: line 489 (g_mime_object_add_header): assertion `GMIME_IS_OBJECT (object)' failed (process:1774): gmime-CRITICAL **: file gmime-object.c: line 489 (g_mime_object_add_header): assertion `GMIME_IS_OBJECT (object)' failed (process:1774): gmime-CRITICAL **: file gmime-object.c: line 489 (g_mime_object_add_header): assertion `GMIME_IS_OBJECT (object)' failed (process:1774): gmime-CRITICAL **: file gmime-object.c: line 489 (g_mime_object_add_header): assertion `GMIME_IS_OBJECT (object)' failed (process:1774): gmime-CRITICAL **: file gmime-object.c: line 489 (g_mime_object_add_header): assertion `GMIME_IS_OBJECT (object)' failed (process:1774): gmime-CRITICAL **: file gmime-object.c: line 489 (g_mime_object_add_header): assertion `GMIME_IS_OBJECT (object)' failed (process:1774): gmime-CRITICAL **: file gmime-object.c: line 489 (g_mime_object_add_header): assertion `GMIME_IS_OBJECT (object)' failed (process:1774): gmime-CRITICAL **: file gmime-object.c: line 489 (g_mime_object_add_header): assertion `GMIME_IS_OBJECT (object)' failed (process:1774): gmime-CRITICAL **: file gmime-object.c: line 489 (g_mime_object_add_header): assertion `GMIME_IS_OBJECT (object)' failed (process:1774): gmime-CRITICAL **: file gmime-object.c: line 489 (g_mime_object_add_header): assertion `GMIME_IS_OBJECT (object)' failed (process:1774): gmime-CRITICAL **: file gmime-object.c: line 489 (g_mime_object_add_header): assertion `GMIME_IS_OBJECT (object)' failed (process:1774): gmime-CRITICAL **: file gmime-object.c: line 489 (g_mime_object_add_header): assertion `GMIME_IS_OBJECT (object)' failed (process:1774): gmime-CRITICAL **: file gmime-object.c: line 489 (g_mime_object_add_header): assertion `GMIME_IS_OBJECT (object)' failed (process:1774): gmime-CRITICAL **: file gmime-object.c: line 489 (g_mime_object_add_header): assertion `GMIME_IS_OBJECT (object)' failed (process:1774): gmime-CRITICAL **: file gmime-object.c: line 325 (g_mime_object_set_content_type): assertion `GMIME_IS_OBJECT (object)' failed (process:1774): gmime-CRITICAL **: file gmime-part.c: line 799 (g_mime_part_get_encoding): assertion `GMIME_IS_PART (mime_part)' failed (process:1774): gmime-CRITICAL **: file gmime-part.c: line 1160 (g_mime_part_set_content_object): assertion `GMIME_IS_PART (mime_part)' failed (process:1774): gmime-CRITICAL **: file gmime-object.c: line 148 (g_mime_object_ref): assertion `GMIME_IS_OBJECT (object)' failed (process:1774): gmime-CRITICAL **: file gmime-object.c: line 163 (g_mime_object_unref): assertion `GMIME_IS_OBJECT (object)' failed ==1774== Invalid free() / delete / delete[] ==1774== at 0x40029B6B: free (vg_replace_malloc.c:220) ==1774== by 0x407493DB: free_mem (in /lib/libc-2.3.1.so) ==1774== by 0x406B4FB1: __GI___libc_freeres (in /lib/libc-2.3.1.so) ==1774== by 0x40186821: vgPlain___libc_freeres_wrapper (vg_intercept.c:831) ==1774== by 0x4066825F: __GI_exit (in /lib/libc-2.3.1.so) ==1774== by 0x40651BBB: __libc_start_main (in /lib/libc-2.3.1.so) ==1774== by 0x8048830: (within /tmp/t3) ==1774== Address 0x409A1370 is not stack'd, malloc'd or free'd ==1774== ==1774== ERROR SUMMARY: 2 errors from 1 contexts (suppressed: 0 from 0) ==1774== malloc/free: in use at exit: 56904 bytes in 346 blocks. ==1774== malloc/free: 2644 allocs, 2300 frees, 317928 bytes allocated. ==1774== For counts of detected errors, rerun with: -v ==1774== searching for pointers to 346 not-freed blocks. ==1774== checked 11772236 bytes. ==1774== ==1774== ==1774== 16 bytes in 1 blocks are definitely lost in loss record 1 of 9 ==1774== at 0x40029D71: calloc (vg_replace_malloc.c:273) ==1774== by 0x402BA760: g_malloc0 (gmem.c:153) ==1774== by 0x4024EC22: g_mime_content_type_new (gmime-content-type.c:71) ==1774== by 0x4026622D: parser_construct_message (gmime-parser.c:1310) ==1774== by 0x804896F: main (in /tmp/t3) ==1774== by 0x40651BB3: __libc_start_main (in /lib/libc-2.3.1.so) ==1774== by 0x8048830: (within /tmp/t3) ==1774== ==1774== ==1774== 80 bytes in 1 blocks are still reachable in loss record 2 of 9 ==1774== at 0x40029889: malloc (vg_replace_malloc.c:153) ==1774== by 0x406526C9: __gconv_open (in /lib/libc-2.3.1.so) ==1774== by 0x40652227: iconv_open (in /lib/libc-2.3.1.so) ==1774== by 0x402A0695: try_conversion (gconvert.c:64) ==1774== by 0x402A0742: g_iconv_open (gconvert.c:115) ==1774== by 0x402A0D64: open_converter (gconvert.c:379) ==1774== by 0x402A0FEC: g_convert (gconvert.c:502) ==1774== by 0x402A1478: g_convert_with_fallback (gconvert.c:714) ==1774== by 0x402BCF38: strdup_convert (gmessages.c:541) ==1774== by 0x402BD894: g_log_default_handler (gmessages.c:803) ==1774== by 0x402BCC74: g_logv (gmessages.c:493) ==1774== by 0x402BCE83: g_log (gmessages.c:527) ==1774== ==1774== ==1774== 116 bytes in 1 blocks are still reachable in loss record 3 of 9 ==1774== at 0x40029889: malloc (vg_replace_malloc.c:153) ==1774== by 0x4065E16C: __newlocale (in /lib/libc-2.3.1.so) ==1774== by 0x405A20ED: std::locale::facet::_S_create_c_locale(__locale_struct*&, char const*, __locale_struct*) (c++locale.cc:170) ==1774== by 0x405A3019: std::locale::facet::facet(unsigned) (locale.cc:368) ==1774== by 0x405A339F: std::ctype<char>::ctype(unsigned short const*, bool, unsigned) (/tmp/gcc-3.2/i686-ssc-linux/libstdc++-v3/include/bits/locale_facets.h:124) ==1774== by 0x405A66EA: std::locale::_Impl::_Impl(std::locale::facet**, unsigned, bool) (../libsupc++/new:89) ==1774== by 0x405A2DEB: std::locale::classic() (../libsupc++/new:89) ==1774== by 0x405A2394: std::locale::locale() (/tmp/gcc-3.2/i686-ssc-linux/libstdc++-v3/include/bits/localefwd.h:279) ==1774== by 0x405D1786: std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf() (/tmp/gcc-3.2/i686-ssc-linux/libstdc++-v3/include/streambuf:356) ==1774== by 0x405D04E1: __gnu_cxx::stdio_filebuf<char, std::char_traits<char> >::stdio_filebuf(_IO_FILE*, std::_Ios_Openmode, int) (/tmp/gcc-3.2/i686-ssc-linux/libstdc++-v3/include/ext/stdio_filebuf.h:144) ==1774== by 0x4059C596: std::ios_base::Init::_S_ios_create(bool) (../libsupc++/new:89) ==1774== by 0x4059CB64: std::ios_base::Init::Init() (ios.cc:205) ==1774== ==1774== ==1774== 800 bytes in 20 blocks are possibly lost in loss record 4 of 9 ==1774== at 0x40029D71: calloc (vg_replace_malloc.c:273) ==1774== by 0x402BA760: g_malloc0 (gmem.c:153) ==1774== by 0x4078E1C8: type_node_any_new_W (gtype.c:290) ==1774== by 0x4078E534: type_node_fundamental_new_W (gtype.c:392) ==1774== by 0x40795D38: g_type_init_with_debug_flags (gtype.c:3057) ==1774== by 0x40795ECF: g_type_init (gtype.c:3115) ==1774== by 0x8048936: main (in /tmp/t3) ==1774== by 0x40651BB3: __libc_start_main (in /lib/libc-2.3.1.so) ==1774== by 0x8048830: (within /tmp/t3) ==1774== ==1774== ==1774== 2232 bytes in 8 blocks are still reachable in loss record 5 of 9 ==1774== at 0x40029E8B: realloc (vg_replace_malloc.c:299) ==1774== by 0x402BA7EC: g_realloc (gmem.c:169) ==1774== by 0x4029F421: bsearch_array_insert (gbsearcharray.c:82) ==1774== by 0x407762C2: g_boxed_type_register_static (gboxed.c:324) ==1774== by 0x40775D66: g_value_array_get_type (gboxed.c:163) ==1774== by 0x40783E67: g_param_spec_types_init (gparamspecs.c:1320) ==1774== by 0x40795DEC: g_type_init_with_debug_flags (gtype.c:3099) ==1774== by 0x40795ECF: g_type_init (gtype.c:3115) ==1774== by 0x8048936: main (in /tmp/t3) ==1774== by 0x40651BB3: __libc_start_main (in /lib/libc-2.3.1.so) ==1774== by 0x8048830: (within /tmp/t3) ==1774== ==1774== ==1774== 2456 bytes in 52 blocks are still reachable in loss record 6 of 9 ==1774== at 0x40029889: malloc (vg_replace_malloc.c:153) ==1774== by 0x40029E18: realloc (vg_replace_malloc.c:291) ==1774== by 0x402BA7EC: g_realloc (gmem.c:169) ==1774== by 0x402A3D7A: g_quark_new (gdataset.c:625) ==1774== by 0x402A3BAF: g_quark_from_static_string (gdataset.c:600) ==1774== by 0x40795CC6: g_type_init_with_debug_flags (gtype.c:3044) ==1774== by 0x40795ECF: g_type_init (gtype.c:3115) ==1774== by 0x8048936: main (in /tmp/t3) ==1774== by 0x40651BB3: __libc_start_main (in /lib/libc-2.3.1.so) ==1774== by 0x8048830: (within /tmp/t3) ==1774== ==1774== ==1774== 4972 bytes in 137 blocks are still reachable in loss record 7 of 9 ==1774== at 0x40029D71: calloc (vg_replace_malloc.c:273) ==1774== by 0x402BA760: g_malloc0 (gmem.c:153) ==1774== by 0x4078F93F: type_data_make_W (gtype.c:935) ==1774== by 0x40795DB9: g_type_init_with_debug_flags (gtype.c:3066) ==1774== by 0x40795ECF: g_type_init (gtype.c:3115) ==1774== by 0x8048936: main (in /tmp/t3) ==1774== by 0x40651BB3: __libc_start_main (in /lib/libc-2.3.1.so) ==1774== by 0x8048830: (within /tmp/t3) ==1774== ==1774== ==1774== 13592 bytes in 125 blocks are still reachable in loss record 8 of 9 ==1774== at 0x40029889: malloc (vg_replace_malloc.c:153) ==1774== by 0x402BA6E8: g_malloc (gmem.c:136) ==1774== by 0x402A9D4E: g_hash_table_new_full (ghash.c:145) ==1774== by 0x402A9D25: g_hash_table_new (ghash.c:115) ==1774== by 0x402A3BCD: g_quark_from_static_string (gdataset.c:595) ==1774== by 0x40795CC6: g_type_init_with_debug_flags (gtype.c:3044) ==1774== by 0x40795ECF: g_type_init (gtype.c:3115) ==1774== by 0x8048936: main (in /tmp/t3) ==1774== by 0x40651BB3: __libc_start_main (in /lib/libc-2.3.1.so) ==1774== by 0x8048830: (within /tmp/t3) ==1774== ==1774== ==1774== 32640 bytes in 1 blocks are still reachable in loss record 9 of 9 ==1774== at 0x40029889: malloc (vg_replace_malloc.c:153) ==1774== by 0x406527CE: __gconv_open (in /lib/libc-2.3.1.so) ==1774== by 0x40652227: iconv_open (in /lib/libc-2.3.1.so) ==1774== by 0x402A0695: try_conversion (gconvert.c:64) ==1774== by 0x402A0742: g_iconv_open (gconvert.c:115) ==1774== by 0x402A0D64: open_converter (gconvert.c:379) ==1774== by 0x402A0FEC: g_convert (gconvert.c:502) ==1774== by 0x402A1478: g_convert_with_fallback (gconvert.c:714) ==1774== by 0x402BCF38: strdup_convert (gmessages.c:541) ==1774== by 0x402BD894: g_log_default_handler (gmessages.c:803) ==1774== by 0x402BCC74: g_logv (gmessages.c:493) ==1774== by 0x402BCE83: g_log (gmessages.c:527) ==1774== ==1774== LEAK SUMMARY: ==1774== definitely lost: 16 bytes in 1 blocks. ==1774== possibly lost: 800 bytes in 20 blocks. ==1774== still reachable: 56088 bytes in 325 blocks. ==1774== suppressed: 0 bytes in 0 blocks. ==1774==
It's expected that GLib will have allocated memory at exit - it uses caches in various places to greatly improve performance: The "definitely lost" memory in the trace above is a GMime bug (I'm hoping that you reported that separately) The "possibly lost" memory is probably because GObject stores references to typenodes with a pointer not at the beginning of the memory block (bug 66199 is about Purify having trouble with that.) The other stuff isn't a bug at all, though bug 64096 asks for a function to call at shutdown to free all of GLib's caches. *** This bug has been marked as a duplicate of 64096 ***