GNOME Bugzilla – Bug 490876
Patch: Memory leaks etc.
Last modified: 2021-05-26 09:58:07 UTC
Please describe the problem: Hi, Please find attached a patch to fix a number of memory leaks and small issues (one misuse of delete[] for malloc()ed memory, one use of unititialized variable, a typo fix for a debug output string). Valgrind still reports a few more interesting memory leaks. Here it seems the CAlphabetManager module never gets freed: 18,018 (240 direct, 17,778 indirect) bytes in 1 blocks are definitely lost in loss record 187 of 245 at 0x4C22425: operator new(unsigned long) (vg_replace_malloc.c:167) by 0x516203: Dasher::CAlphabetManagerFactory::CAlphabetManagerFactory(Dasher::CDasherInterfaceBase*, Dasher::CEventHandler*, CSettingsStore*, Dasher::CAlphIO*, CNodeCreationManager*) (AlphabetManagerFactory.cpp:39) by 0x4E0653: CNodeCreationManager::CNodeCreationManager(Dasher::CDasherInterfaceBase*, Dasher::CEventHandler*, CSettingsStore*, Dasher::CAlphIO*) (NodeCreationManager.cpp:19) This one alarms me, but I can't see how it can be dasher's fault, probably a leak in Cairo: 21,760 bytes in 1,360 blocks are definitely lost in loss record 221 of 245 at 0x4C21C16: malloc (vg_replace_malloc.c:149) by 0x8DAEC12: (within /usr/lib/libcairo.so.2.11.5) by 0x8DB0C1E: (within /usr/lib/libcairo.so.2.11.5) by 0x8D8A103: (within /usr/lib/libcairo.so.2.11.5) by 0x8D89365: (within /usr/lib/libcairo.so.2.11.5) by 0x8D89A2E: (within /usr/lib/libcairo.so.2.11.5) by 0x8D87384: (within /usr/lib/libcairo.so.2.11.5) by 0x8D7A8FB: (within /usr/lib/libcairo.so.2.11.5) by 0x8D7419F: cairo_fill_preserve (in /usr/lib/libcairo.so.2.11.5) by 0x8D741B8: cairo_fill (in /usr/lib/libcairo.so.2.11.5) by 0x4BCD4D: CCanvas::DrawRectangle(int, int, int, int, int, int, Dasher::Opts::ColorSchemes, bool, bool, int) (Canvas.cpp:235) by 0x4D473C: Dasher::CDasherView::DasherDrawRectangle(long long, long long, long long, long long, int, int, Dasher::Opts::ColorSchemes, bool, bool, int) (DasherView.cpp:198) And this one is big, but could't figure it out in the few hours I looked at dasher. The statement causing it in dasher_editor_internal_new() is a gtk_container_add(): 511,296 (183,040 direct, 328,256 indirect) bytes in 357 blocks are definitely lost in loss record 237 of 245 at 0x4C21D17: realloc (vg_replace_malloc.c:306) by 0x7BD22D2: (within /usr/lib/libfontconfig.so.1.2.0) by 0x7BD2C45: (within /usr/lib/libfontconfig.so.1.2.0) by 0x7BCFB35: FcFontRenderPrepare (in /usr/lib/libfontconfig.so.1.2.0) by 0xBB6FDC0: (within /usr/lib/libpangoft2-1.0.so.0.1800.3) by 0x8B3E67C: (within /usr/lib/libpango-1.0.so.0.1800.3) by 0x8B3E97B: pango_itemize_with_base_dir (in /usr/lib/libpango-1.0.so.0.1800.3) by 0x8B46839: (within /usr/lib/libpango-1.0.so.0.1800.3) by 0x8B478E0: (within /usr/lib/libpango-1.0.so.0.1800.3) by 0xBB6CC47: pango_fc_font_create_metrics_for_context (in /usr/lib/libpangoft2-1.0.so.0.1800.3) by 0x79B2E8F: (within /usr/lib/libpangocairo-1.0.so.0.1800.3) by 0x8B448CE: pango_layout_line_get_extents (in /usr/lib/libpango-1.0.so.0.1800.3) by 0x8B44B56: (within /usr/lib/libpango-1.0.so.0.1800.3) by 0x8B47A55: (within /usr/lib/libpango-1.0.so.0.1800.3) by 0x6F0FF67: gtk_text_layout_get_line_display (gtktextlayout.c:2398) by 0x6F13701: gtk_text_layout_real_wrap (gtktextlayout.c:1152) by 0x6EF3E76: _gtk_text_btree_validate_line (gtktextbtree.c:5402) by 0x6F12606: gtk_text_layout_validate_yrange (gtktextlayout.c:1067) by 0x6F1E065: gtk_text_view_validate_onscreen (gtktextview.c:3335) by 0x6F1E10B: gtk_text_view_value_changed (gtktextview.c:7053) by 0xA126A1E: g_closure_invoke (gclosure.c:490) by 0xA13AAD9: signal_emit_unlocked_R (gsignal.c:2478) by 0xA13C134: g_signal_emit_valist (gsignal.c:2199) by 0xA13C522: g_signal_emit (gsignal.c:2243) by 0x6F79DAE: gtk_widget_set_scroll_adjustments (gtkwidget.c:4742) by 0x6EC4224: gtk_scrolled_window_add (gtkscrolledwindow.c:1625) by 0xA126A1E: g_closure_invoke (gclosure.c:490) by 0xA13A3BD: signal_emit_unlocked_R (gsignal.c:2370) by 0xA13C134: g_signal_emit_valist (gsignal.c:2199) by 0xA13C522: g_signal_emit (gsignal.c:2243) by 0x4AD616: dasher_editor_internal_new (dasher_editor_internal.cpp:302) by 0x4A2999: create_dasher_editor (dasher_main.cpp:1342) by 0x54B2535: (within /usr/lib/libglade-2.0.so.0.0.7) by 0x54B49A1: glade_xml_build_widget (in /usr/lib/libglade-2.0.so.0.0.7) by 0x54BCCAF: (within /usr/lib/libglade-2.0.so.0.0.7) by 0x54B4212: glade_xml_set_common_params (in /usr/lib/libglade-2.0.so.0.0.7) by 0x54B49DF: glade_xml_build_widget (in /usr/lib/libglade-2.0.so.0.0.7) by 0x54B4C42: glade_standard_build_children (in /usr/lib/libglade-2.0.so.0.0.7) by 0x54B4212: glade_xml_set_common_params (in /usr/lib/libglade-2.0.so.0.0.7) by 0x54B49DF: glade_xml_build_widget (in /usr/lib/libglade-2.0.so.0.0.7) by 0x54B4C42: glade_standard_build_children (in /usr/lib/libglade-2.0.so.0.0.7) by 0x54B4212: glade_xml_set_common_params (in /usr/lib/libglade-2.0.so.0.0.7) by 0x54B49DF: glade_xml_build_widget (in /usr/lib/libglade-2.0.so.0.0.7) by 0x54B4D99: (within /usr/lib/libglade-2.0.so.0.0.7) by 0x54B4F92: glade_xml_construct (in /usr/lib/libglade-2.0.so.0.0.7) by 0x54B5035: glade_xml_new (in /usr/lib/libglade-2.0.so.0.0.7) by 0x4A41B7: dasher_main_load_interface(_DasherMain*) (dasher_main.cpp:429) by 0x4A471C: dasher_main_new (dasher_main.cpp:288) by 0x4A210C: main (main.cc:239) This one is surprising since I can't figure out what should be left here after the glade xml object is destroyed (and I verified it is). Unless the glade xml thing shares the allocator with something else, in which case it's probably just a false alarm: 531,968 bytes in 416 blocks are possibly lost in loss record 241 of 245 at 0x4C20E3D: memalign (vg_replace_malloc.c:332) by 0x4C20E96: posix_memalign (vg_replace_malloc.c:425) by 0xA3A7CB9: slab_allocator_alloc_chunk (gslice.c:1136) by 0xA3A8B10: g_slice_alloc (gslice.c:666) by 0xA3A8C05: g_slice_alloc0 (gslice.c:833) by 0xA145FBE: g_type_create_instance (gtype.c:1549) by 0xA12BDAC: g_object_constructor (gobject.c:1046) by 0xA12C39F: g_object_newv (gobject.c:937) by 0xA12CEA1: g_object_new_valist (gobject.c:986) by 0xA12CFE0: g_object_new (gobject.c:795) by 0x6E30303: gtk_hbox_new (gtkhbox.c:63) by 0x6E21E71: gtk_file_selection_init (gtkfilesel.c:684) by 0xA146423: g_type_create_instance (gtype.c:1569) by 0xA12BDAC: g_object_constructor (gobject.c:1046) by 0xA12C39F: g_object_newv (gobject.c:937) by 0x54B3C23: glade_standard_build_widget (in /usr/lib/libglade-2.0.so.0.0.7) by 0x54B4B35: glade_xml_build_widget (in /usr/lib/libglade-2.0.so.0.0.7) by 0x54B4D99: (within /usr/lib/libglade-2.0.so.0.0.7) by 0x54B4F92: glade_xml_construct (in /usr/lib/libglade-2.0.so.0.0.7) by 0x54B5035: glade_xml_new (in /usr/lib/libglade-2.0.so.0.0.7) by 0x4A41B7: dasher_main_load_interface(_DasherMain*) (dasher_main.cpp:429) by 0x4A471C: dasher_main_new (dasher_main.cpp:288) by 0x4A210C: main (main.cc:239) Steps to reproduce: Run dasher under valgrind --leak-check=full Actual results: Expected results: Does this happen every time? Other information:
Created attachment 97982 [details] [review] Patch to fix mem leaks and a few other small issues Here's the patch. I tried to follow your coding conventions. I forgot to mention, the patch is against svn HEAD.
Thanks for this - I've now applied the patch to trunk. Keeping the bug open pending investigation of the remaining leaks.
In attachment 97982 [details] [review], the call to delete[] cairo_colours; Should have been surrounded with an "#if WITH_CAIRO".
(In reply to comment #3) > In attachment 97982 [details] [review] [edit], the call to > delete[] cairo_colours; > Should have been surrounded with an "#if WITH_CAIRO". Applied in r3465.
valgrind now gives different interesting leaks - this bug could be permanently open: "remember to try valgrind"
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org. As part of that, we are mass-closing older open tickets in bugzilla.gnome.org which have not seen updates for a longer time (resources are unfortunately quite limited so not every ticket can get handled). If you can still reproduce the situation described in this ticket in a recent and supported software version, then please follow https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines and create a new enhancement request ticket at https://gitlab.gnome.org/GNOME/dasher/-/issues/ Thank you for your understanding and your help.