GNOME Bugzilla – Bug 300736
Plug a bunch of leaks in the registry code
Last modified: 2005-04-17 20:43:56 UTC
Attaching a patch. Seems to work with no errors from valgrind at least.
Damn, I need regular CVS access before I can post the patch. Will do so later today
Created attachment 45297 [details] [review] patch for leaks and warnings
A few gcc4 warnin fixes crept in here too, hope that doesn't cause problems.
There's something not quite right about that patch. It caused totem to segfault when opening an mpeg file. Attaching backtraces for the leaks that the patch was supposed to fix, this time from running totem. ==31516== 5769 bytes in 316 blocks are definitely lost in loss record 181 of 206 ==31516== at 0x3414E222: malloc (vg_replace_malloc.c:130) ==31516== by 0x34927E4E: xmlStrndup (xmlstring.c:45) ==31516== by 0x34927EAD: xmlStrdup (xmlstring.c:71) ==31516== by 0x34928536: xmlStrcat (xmlstring.c:519) ==31516== by 0x348DF659: xmlNodeListGetString (tree.c:1614) ==31516== by 0x348E25A8: xmlGetProp (tree.c:6045) ==31516== by 0x34953B37: xmlTextReaderGetAttribute (xmlreader.c:2237) ==31516== by 0x34392650: load_plugin (gstlibxmlregistry.c:703) ==31516== by 0x34392E21: gst_xml_registry_load (gstlibxmlregistry.c:922) ==31516== by 0x3438905B: gst_registry_load (gstregistry.c:125) ==31516== by 0x34389B55: _registry_load_func (gstregistrypool.c:110) ==31516== by 0x34CDC953: g_list_foreach (glist.c:670) ==31516== by 0x34389B7F: gst_registry_pool_load_all (gstregistrypool.c:125) ==31516== by 0x3434E7B4: init_post (gst.c:638) ==31516== by 0x3434ED4C: init_popt_callback (gst.c:807) ==31516== by 0x34C74464: (within /usr/lib/libpopt.so.0.0.0) ==31516== by 0x34C74478: (within /usr/lib/libpopt.so.0.0.0) ==31516== by 0x34C74478: (within /usr/lib/libpopt.so.0.0.0) ==31516== by 0x34C76219: poptGetNextOpt (in /usr/lib/libpopt.so.0.0.0) ==31516== by 0x342BA170: gnome_program_parse_args (gnome-program.c:1457) ==31516== by 0x342BA801: gnome_program_init_common (gnome-program.c:1865) ==31516== by 0x342BAACC: gnome_program_init (gnome-program.c:1684) ==31516== by 0x805F1D2: main (totem.c:3344) and another one: ==31516== 1577 (1453 direct, 124 indirect) bytes in 99 blocks are definitely lost in loss record 162 of 206 ==31516== at 0x3414E222: malloc (vg_replace_malloc.c:130) ==31516== by 0x34CE5585: g_malloc (gmem.c:137) ==31516== by 0x34CF5869: g_strdup (gstrfuncs.c:91) ==31516== by 0x3439238D: read_string (gstlibxmlregistry.c:590) ==31516== by 0x34392B0F: load_plugin (gstlibxmlregistry.c:759) ==31516== by 0x34392E21: gst_xml_registry_load (gstlibxmlregistry.c:922) ==31516== by 0x3438905B: gst_registry_load (gstregistry.c:125) ==31516== by 0x34389B55: _registry_load_func (gstregistrypool.c:110) ==31516== by 0x34CDC953: g_list_foreach (glist.c:670) ==31516== by 0x34389B7F: gst_registry_pool_load_all (gstregistrypool.c:125) ==31516== by 0x3434E7B4: init_post (gst.c:638) ==31516== by 0x3434ED4C: init_popt_callback (gst.c:807) ==31516== by 0x34C74464: (within /usr/lib/libpopt.so.0.0.0) ==31516== by 0x34C74478: (within /usr/lib/libpopt.so.0.0.0) ==31516== by 0x34C74478: (within /usr/lib/libpopt.so.0.0.0) ==31516== by 0x34C76219: poptGetNextOpt (in /usr/lib/libpopt.so.0.0.0) ==31516== by 0x342BA170: gnome_program_parse_args (gnome-program.c:1457) ==31516== by 0x342BA801: gnome_program_init_common (gnome-program.c:1865) ==31516== by 0x342BAACC: gnome_program_init (gnome-program.c:1684) ==31516== by 0x805F1D2: main (totem.c:3344)
You free values added using add_char_array(), whereas that function already takes ownership of the value. I'm working on a slightly modified patch that uses a read_string_const(), to prevent excessive malloc/free turns. Not that it matters much, but hey, if we can, why not just do it.
Created attachment 45348 [details] [review] alternative patch This seems to work for me. Does it solve all memleaks?
Also, please separate the gcc4-patch from the memleak patch, just for my sanity and yours. :).
Hm, the read_const() idea seems to be a bad idea, let me revert that...
Created attachment 45350 [details] [review] x OK, so this is your original patch w/o the casts and w/o the free-on-add_to_array.
applied, closing. Please file another bug report for the gcc4 stuff so I can do all that at once.