Memory leaks (Valgrind)

156 views
Skip to first unread message

Jaime Machado

unread,
Jan 29, 2015, 7:15:26 PM1/29/15
to mat...@googlegroups.com
Hi,
I'm getting memory leaks when I test this sample program with valgrind. The test program only creates the FLTK window and exits. The log goes attached since it's large.

Command used: sudo valgrind --leak-check=full --show-leak-kinds=all --undef-value-errors=no ./mathGL2

Using mathGL SVN rev.1118, Ubuntu 14.04. Program compiled with debug info.

#include <mgl2/fltk.h>

int main(int argc,char **argv) {
	mglFLTK gr("test");
	return 0;
}


==14119== HEAP SUMMARY:
==14119==     in use at exit: 44,064,801 bytes in 1,215 blocks
==14119==   total heap usage: 14,319 allocs, 13,104 frees, 230,786,446 bytes allocated

[...]

==14119== LEAK SUMMARY:
==14119==    definitely lost: 6,040 bytes in 2 blocks
==14119==    indirectly lost: 29 bytes in 1 blocks
==14119==      possibly lost: 42,374 bytes in 22 blocks
==14119==    still reachable: 44,016,358 bytes in 1,190 blocks
==14119==         suppressed: 0 bytes in 0 blocks

Best regards,
Jaime
val.txt

mathgl....@gmail.com

unread,
Jan 30, 2015, 3:38:39 PM1/30/15
to mat...@googlegroups.com
Dear Jaime,

most probably these memory leaks are caused by libc or fltk itself. Because it is absemt at Kubuntu 14.10 and at Debian sid. At this, I see it on Ubuntu 14.04 only.

--
You received this message because you are subscribed to the Google Groups "MathGL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathgl+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Kind regards,
Alexey Balakin

Jaime Machado

unread,
Feb 1, 2015, 4:25:07 PM2/1/15
to mat...@googlegroups.com
Alexey,

Do you have suggestions on how to solve this? I built from source the latest FLTK version (1.3.3) and in their foruns they say they check everything with valgrind and have no memory leaks.My GNU C lib is version 2.19.
Can you give me the versions of these libs that work well for you? I'm installing Kubuntu 14.04, do you think It will solve the issue? Thanks.

Best regards,
Jaime

mathgl....@gmail.com

unread,
Feb 2, 2015, 1:33:18 AM2/2/15
to mat...@googlegroups.com
Dear Jaime,

I have no idea. I just can show my valgrind output (Kubuntu 14.10) with some comments.

==32235== Memcheck, a memory error detector
==32235== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==32235== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
==32235== Command: ./a.out
==32235== Parent PID: 29963
==32235==
==32235==
==32235== HEAP SUMMARY:
==32235==     in use at exit: 44,062,316 bytes in 1,639 blocks
==32235==   total heap usage: 14,184 allocs, 12,545 frees, 188,943,336 bytes allocated
==32235==
==32235== 30 bytes in 1 blocks are possibly lost in loss record 85 of 313
==32235==    at 0x4C2B100: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==32235==    by 0x56F6668: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==32235==    by 0x56F66F3: std::string::_M_mutate(unsigned long, unsigned long, unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==32235==    by 0x56F6D2D: std::string::_M_replace_safe(unsigned long, unsigned long, char const*, unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==32235==    by 0x51732C4: assign (basic_string.h:1149)
==32235==    by 0x51732C4: operator= (basic_string.h:563)
==32235==    by 0x51732C4: mglCanvas::mglCanvas(int, int) (canvas.cpp:33)
==32235==    by 0x52ECAD2: mglCanvasWnd::mglCanvasWnd() (window.cpp:22)
==32235==    by 0x4E700B8: mglCanvasFL (fltk.cpp:649)
==32235==    by 0x4E700B8: mgl_create_graph_fltk (fltk.cpp:727)
==32235==    by 0x400ED6: mglFLTK::mglFLTK(char const*) (in /home/balakin/tmp/a.out)
==32235==    by 0x400C75: main (in /home/balakin/tmp/a.out)

This line
canvas.cpp:33:    fscl=ftet=0;        PlotId = "frame";
can produce "lost" memory only if destructor was not called. Most probably this cause other "possibly lost" and "still reachable" records. Probably this is my bug, but I'm not sure here.


==32235==
==32235== 70 (24 direct, 46 indirect) bytes in 1 blocks are definitely lost in loss record 167 of 313
==32235==    at 0x4C2ABA0: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==32235==    by 0x5F3EAEE: XCreateFontSet (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==32235==    by 0x4E8CAF4: fl_new_ic() (in /usr/local/lib/libmgl-fltk.so.7.4.0)
==32235==    by 0x4E8CE44: fl_init_xim() (in /usr/local/lib/libmgl-fltk.so.7.4.0)
==32235==    by 0x4E8D289: fl_open_display(_XDisplay*) (in /usr/local/lib/libmgl-fltk.so.7.4.0)
==32235==    by 0x4E8B1A5: Fl::get_system_colors() (in /usr/local/lib/libmgl-fltk.so.7.4.0)
==32235==    by 0x4E8A82B: Fl_Window::show(int, char**) (in /usr/local/lib/libmgl-fltk.so.7.4.0)
==32235==    by 0x4E70287: Window (fltk.cpp:722)
==32235==    by 0x4E70287: mgl_create_graph_fltk (fltk.cpp:728)
==32235==    by 0x400ED6: mglFLTK::mglFLTK(char const*) (in /home/balakin/tmp/a.out)
==32235==    by 0x400C75: main (in /home/balakin/tmp/a.out)

This one is caused by FLTK. At least I see no problem in my part at line
fltk.cpp:722:    Wnd->show(argv ? argc:0, argv ? argv:tmp);

...

==32235== LEAK SUMMARY:
==32235==    definitely lost: 24 bytes in 1 blocks==32235==    indirectly lost: 46 bytes in 1 blocks
==32235==      possibly lost: 44,246 bytes in 25 blocks
==32235==    still reachable: 44,018,000 bytes in 1,612 blocks
==32235==         suppressed: 0 bytes in 0 blocks

Jaime Machado

unread,
Feb 2, 2015, 10:26:23 AM2/2/15
to mat...@googlegroups.com
Alexey,

I installed Ubuntu 14.10 (not Kubuntu) with gnome and the test program now has different results with valgrind. I'll put them here in hope it will help you in some way. I don't know what to do and I'll leave it at that for now.

Detailed log goes attached.

jaime@jaime-U36SG:~/tese/mathGL2$ sudo valgrind --leak-check=full --undef-value-errors=no ./mathGL2
==11114== Memcheck, a memory error detector
==11114== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==11114== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
==11114== Command: ./mathGL2
==11114== 
==11114== 
==11114== HEAP SUMMARY:
==11114==     in use at exit: 44,035,997 bytes in 1,186 blocks
==11114==   total heap usage: 14,018 allocs, 12,832 frees, 188,879,206 bytes allocated
==11114== 
==11114== 30 bytes in 1 blocks are possibly lost in loss record 93 of 320
==11114==    at 0x4C2B100: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11114==    by 0x5615668: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==11114==    by 0x56156F3: std::string::_M_mutate(unsigned long, unsigned long, unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==11114==    by 0x5615D2D: std::string::_M_replace_safe(unsigned long, unsigned long, char const*, unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==11114==    by 0x4EA5BA3: mglCanvas::mglCanvas(int, int) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x5003CD2: mglCanvasWnd::mglCanvasWnd() (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x534A09C: mgl_create_graph_fltk (in /usr/local/lib/libmgl-fltk.so.7.4.0)
==11114==    by 0x400F1D: mglFLTK::mglFLTK(char const*) (fltk.h:49)
==11114==    by 0x400C97: main (main.cpp:31)
==11114== 
==11114== 344 bytes in 5 blocks are possibly lost in loss record 257 of 320
==11114==    at 0x4C2B100: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11114==    by 0x56184FE: std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_Rep::_S_create(unsigned long, unsigned long, std::allocator<wchar_t> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==11114==    by 0x56191F8: std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_Rep::_M_clone(std::allocator<wchar_t> const&, unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==11114==    by 0x56192AF: std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::reserve(unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==11114==    by 0x4EA3B31: mgl_ftoa(double, char const*) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x4E79FCA: mgl_tick_text(double, double, double, double, int, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, double, char const*) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x4E7F8E8: mglCanvas::LabelTicks(mglAxis&) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x4E81C34: mglCanvas::AdjustTicks(char const*, bool, std::string) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x4EA1F3F: mglCanvas::DefaultPlotParam() (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x50050EF: mglCanvasWnd::SetDrawFunc(int (*)(mglBase*, void*), void*, void (*)(void*)) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x534A0C7: mgl_create_graph_fltk (in /usr/local/lib/libmgl-fltk.so.7.4.0)
==11114==    by 0x400F1D: mglFLTK::mglFLTK(char const*) (fltk.h:49)
==11114== 
==11114== 344 bytes in 5 blocks are possibly lost in loss record 258 of 320
==11114==    at 0x4C2B100: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11114==    by 0x56184FE: std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_Rep::_S_create(unsigned long, unsigned long, std::allocator<wchar_t> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==11114==    by 0x56191F8: std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_Rep::_M_clone(std::allocator<wchar_t> const&, unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==11114==    by 0x56192AF: std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::reserve(unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==11114==    by 0x4EA3B31: mgl_ftoa(double, char const*) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x4E79FCA: mgl_tick_text(double, double, double, double, int, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, double, char const*) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x4E7F8E8: mglCanvas::LabelTicks(mglAxis&) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x4E81C7E: mglCanvas::AdjustTicks(char const*, bool, std::string) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x4EA1F3F: mglCanvas::DefaultPlotParam() (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x50050EF: mglCanvasWnd::SetDrawFunc(int (*)(mglBase*, void*), void*, void (*)(void*)) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x534A0C7: mgl_create_graph_fltk (in /usr/local/lib/libmgl-fltk.so.7.4.0)
==11114==    by 0x400F1D: mglFLTK::mglFLTK(char const*) (fltk.h:49)
==11114== 
==11114== 344 bytes in 5 blocks are possibly lost in loss record 259 of 320
==11114==    at 0x4C2B100: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11114==    by 0x56184FE: std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_Rep::_S_create(unsigned long, unsigned long, std::allocator<wchar_t> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==11114==    by 0x56191F8: std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_Rep::_M_clone(std::allocator<wchar_t> const&, unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==11114==    by 0x56192AF: std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::reserve(unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==11114==    by 0x4EA3B31: mgl_ftoa(double, char const*) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x4E79FCA: mgl_tick_text(double, double, double, double, int, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, double, char const*) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x4E7F8E8: mglCanvas::LabelTicks(mglAxis&) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x4E81CC8: mglCanvas::AdjustTicks(char const*, bool, std::string) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x4EA1F3F: mglCanvas::DefaultPlotParam() (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x50050EF: mglCanvasWnd::SetDrawFunc(int (*)(mglBase*, void*), void*, void (*)(void*)) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x534A0C7: mgl_create_graph_fltk (in /usr/local/lib/libmgl-fltk.so.7.4.0)
==11114==    by 0x400F1D: mglFLTK::mglFLTK(char const*) (fltk.h:49)
==11114== 
==11114== 344 bytes in 5 blocks are possibly lost in loss record 260 of 320
==11114==    at 0x4C2B100: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11114==    by 0x56184FE: std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_Rep::_S_create(unsigned long, unsigned long, std::allocator<wchar_t> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==11114==    by 0x56191F8: std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_Rep::_M_clone(std::allocator<wchar_t> const&, unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==11114==    by 0x56192AF: std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::reserve(unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==11114==    by 0x4EA3B31: mgl_ftoa(double, char const*) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x4E79FCA: mgl_tick_text(double, double, double, double, int, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, double, char const*) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x4E7F8E8: mglCanvas::LabelTicks(mglAxis&) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x4EA1F3F: mglCanvas::DefaultPlotParam() (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x50050EF: mglCanvasWnd::SetDrawFunc(int (*)(mglBase*, void*), void*, void (*)(void*)) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x534A0C7: mgl_create_graph_fltk (in /usr/local/lib/libmgl-fltk.so.7.4.0)
==11114==    by 0x400F1D: mglFLTK::mglFLTK(char const*) (fltk.h:49)
==11114==    by 0x400C97: main (main.cpp:31)
==11114== 
==11114== 40,968 bytes in 1 blocks are possibly lost in loss record 304 of 320
==11114==    at 0x4C2B820: operator new[](unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11114==    by 0x4EAD161: mglStack<mglGroup>::clear() (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x4EA6020: mglCanvas::ClearFrame() (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x4F924AD: mglCanvas::Clf(mglColor) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x4F52B41: mglCanvas::NewFrame() (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x50050DB: mglCanvasWnd::SetDrawFunc(int (*)(mglBase*, void*), void*, void (*)(void*)) (in /usr/local/lib/libmgl.so.7.4.0)
==11114==    by 0x534A0C7: mgl_create_graph_fltk (in /usr/local/lib/libmgl-fltk.so.7.4.0)
==11114==    by 0x400F1D: mglFLTK::mglFLTK(char const*) (fltk.h:49)
==11114==    by 0x400C97: main (main.cpp:31)
==11114== 
==11114== LEAK SUMMARY:
==11114==    definitely lost: 0 bytes in 0 blocks
==11114==    indirectly lost: 0 bytes in 0 blocks
==11114==      possibly lost: 42,374 bytes in 22 blocks
==11114==    still reachable: 43,993,623 bytes in 1,164 blocks
==11114==         suppressed: 0 bytes in 0 blocks
==11114== Reachable blocks (those to which a pointer was found) are not shown.
==11114== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==11114== 
==11114== For counts of detected and suppressed errors, rerun with: -v
==11114== ERROR SUMMARY: 6 errors from 6 contexts (suppressed: 0 from 0)

Jaime

val3.txt

mathgl....@gmail.com

unread,
Feb 4, 2015, 3:04:55 AM2/4/15
to mat...@googlegroups.com
Dear Jaime,

Yours log is very good. There are no definitely or indirectly memory lost. And there are only some memory which should be cleared at destructor, but probably gcc decide to remove them at exit (for example, if mglGraph object was created entirely in main() function).

--
You received this message because you are subscribed to the Google Groups "MathGL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathgl+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages