Sign in to follow this  
Svenjamin

Is SDL leaking memory?

Recommended Posts

So, I'm using SDL in my current project, and I just started using valgrind to debug and eliminate memory leaks. When I run memcheck, it reports a bunch of leaks, but it doesn't look like most of them are from my code. It appears to be in SDL or system libraries. Here is the output:
==32561== Memcheck, a memory error detector.
==32561== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==32561== Using LibVEX rev 1854, a library for dynamic binary translation.
==32561== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==32561== Using valgrind-3.3.1, a dynamic binary instrumentation framework.
==32561== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==32561== For more details, rerun with: -v
==32561== 
==32561== My PID = 32561, parent PID = 32418.  Prog and args are:
==32561==    bin/linux/Greebles
==32561== 
==32561== Invalid read of size 4
==32561==    at 0x7DCA34: FT_Done_Face (in /usr/lib/libfreetype.so.6.3.16)
==32561==    by 0x4024322: TTF_CloseFont (in /usr/lib/libSDL_ttf-2.0.so.0.6.3)
==32561==    by 0x806BB7E: Framework::Graphics::Font::~Font() (Graphics.h:90)
==32561==    by 0x806BBE0: void boost::checked_delete<Framework::Graphics::Font>(Framework::Graphics::Font*) (checked_delete.hpp:34)
==32561==    by 0x806BCB7: boost::detail::sp_counted_impl_p<Framework::Graphics::Font>::dispose() (sp_counted_impl.hpp:79)
==32561==    by 0x8060D01: boost::detail::sp_counted_base::release() (sp_counted_base_gcc_x86.hpp:145)
==32561==    by 0x8060D39: boost::detail::shared_count::~shared_count() (shared_count.hpp:205)
==32561==    by 0x8061169: boost::shared_ptr<Framework::Graphics::Font>::~shared_ptr() (shared_ptr.hpp:131)
==32561==    by 0x80616CD: std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> >::~pair() (stl_pair.h:69)
==32561==    by 0x806360E: __gnu_cxx::new_allocator<std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> > >::destroy(std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> >*) (new_allocator.h:107)
==32561==    by 0x8067E48: std::_Rb_tree<int, std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> >, std::_Select1st<std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> > >, std::less<int>, std::allocator<std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> > > >::destroy_node(std::_Rb_tree_node<std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> > >*) (stl_tree.h:391)
==32561==    by 0x8067ECD: std::_Rb_tree<int, std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> >, std::_Select1st<std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> > >, std::less<int>, std::allocator<std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> > > >::_M_erase(std::_Rb_tree_node<std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> > >*) (stl_tree.h:1266)
==32561==  Address 0x67db528 is 96 bytes inside a block of size 828 free'd
==32561==    at 0x400543C: free (vg_replace_malloc.c:323)
==32561==    by 0x7D817C: (within /usr/lib/libfreetype.so.6.3.16)
==32561==    by 0x7DB9E9: ft_mem_free (in /usr/lib/libfreetype.so.6.3.16)
==32561==    by 0x7DC9F8: (within /usr/lib/libfreetype.so.6.3.16)
==32561==    by 0x7DCA92: FT_Done_Face (in /usr/lib/libfreetype.so.6.3.16)
==32561==    by 0x7DCB20: FT_Done_Library (in /usr/lib/libfreetype.so.6.3.16)
==32561==    by 0x7D8447: FT_Done_FreeType (in /usr/lib/libfreetype.so.6.3.16)
==32561==    by 0x40233BD: TTF_Quit (in /usr/lib/libSDL_ttf-2.0.so.0.6.3)
==32561==    by 0x805EF7E: Greebles::ShutdownSDL() (Main.cpp:237)
==32561==    by 0x805F855: Greebles::Shutdown() (Main.cpp:188)
==32561==    by 0x8060B74: main (Main.cpp:72)
==32561== 
==32561== Invalid read of size 4
==32561==    at 0x7DCA3B: FT_Done_Face (in /usr/lib/libfreetype.so.6.3.16)
==32561==    by 0x4024322: TTF_CloseFont (in /usr/lib/libSDL_ttf-2.0.so.0.6.3)
==32561==    by 0x806BB7E: Framework::Graphics::Font::~Font() (Graphics.h:90)
==32561==    by 0x806BBE0: void boost::checked_delete<Framework::Graphics::Font>(Framework::Graphics::Font*) (checked_delete.hpp:34)
==32561==    by 0x806BCB7: boost::detail::sp_counted_impl_p<Framework::Graphics::Font>::dispose() (sp_counted_impl.hpp:79)
==32561==    by 0x8060D01: boost::detail::sp_counted_base::release() (sp_counted_base_gcc_x86.hpp:145)
==32561==    by 0x8060D39: boost::detail::shared_count::~shared_count() (shared_count.hpp:205)
==32561==    by 0x8061169: boost::shared_ptr<Framework::Graphics::Font>::~shared_ptr() (shared_ptr.hpp:131)
==32561==    by 0x80616CD: std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> >::~pair() (stl_pair.h:69)
==32561==    by 0x806360E: __gnu_cxx::new_allocator<std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> > >::destroy(std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> >*) (new_allocator.h:107)
==32561==    by 0x8067E48: std::_Rb_tree<int, std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> >, std::_Select1st<std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> > >, std::less<int>, std::allocator<std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> > > >::destroy_node(std::_Rb_tree_node<std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> > >*) (stl_tree.h:391)
==32561==    by 0x8067ECD: std::_Rb_tree<int, std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> >, std::_Select1st<std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> > >, std::less<int>, std::allocator<std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> > > >::_M_erase(std::_Rb_tree_node<std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> > >*) (stl_tree.h:1266)
==32561==  Address 0x4269b00 is 8 bytes inside a block of size 84 free'd
==32561==    at 0x400543C: free (vg_replace_malloc.c:323)
==32561==    by 0x7D817C: (within /usr/lib/libfreetype.so.6.3.16)
==32561==    by 0x7DB9E9: ft_mem_free (in /usr/lib/libfreetype.so.6.3.16)
==32561==    by 0x7DC84E: FT_Remove_Module (in /usr/lib/libfreetype.so.6.3.16)
==32561==    by 0x7DCB3F: FT_Done_Library (in /usr/lib/libfreetype.so.6.3.16)
==32561==    by 0x7D8447: FT_Done_FreeType (in /usr/lib/libfreetype.so.6.3.16)
==32561==    by 0x40233BD: TTF_Quit (in /usr/lib/libSDL_ttf-2.0.so.0.6.3)
==32561==    by 0x805EF7E: Greebles::ShutdownSDL() (Main.cpp:237)
==32561==    by 0x805F855: Greebles::Shutdown() (Main.cpp:188)
==32561==    by 0x8060B74: main (Main.cpp:72)
==32561== 
==32561== Invalid read of size 4
==32561==    at 0x7DC1C9: FT_List_Find (in /usr/lib/libfreetype.so.6.3.16)
==32561==    by 0x7DCA58: FT_Done_Face (in /usr/lib/libfreetype.so.6.3.16)
==32561==    by 0x4024322: TTF_CloseFont (in /usr/lib/libSDL_ttf-2.0.so.0.6.3)
==32561==    by 0x806BB7E: Framework::Graphics::Font::~Font() (Graphics.h:90)
==32561==    by 0x806BBE0: void boost::checked_delete<Framework::Graphics::Font>(Framework::Graphics::Font*) (checked_delete.hpp:34)
==32561==    by 0x806BCB7: boost::detail::sp_counted_impl_p<Framework::Graphics::Font>::dispose() (sp_counted_impl.hpp:79)
==32561==    by 0x8060D01: boost::detail::sp_counted_base::release() (sp_counted_base_gcc_x86.hpp:145)
==32561==    by 0x8060D39: boost::detail::shared_count::~shared_count() (shared_count.hpp:205)
==32561==    by 0x8061169: boost::shared_ptr<Framework::Graphics::Font>::~shared_ptr() (shared_ptr.hpp:131)
==32561==    by 0x80616CD: std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> >::~pair() (stl_pair.h:69)
==32561==    by 0x806360E: __gnu_cxx::new_allocator<std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> > >::destroy(std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> >*) (new_allocator.h:107)
==32561==    by 0x8067E48: std::_Rb_tree<int, std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> >, std::_Select1st<std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> > >, std::less<int>, std::allocator<std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> > > >::destroy_node(std::_Rb_tree_node<std::pair<int const, boost::shared_ptr<Framework::Graphics::Font> > >*) (stl_tree.h:391)
==32561==  Address 0x4269b10 is 24 bytes inside a block of size 84 free'd
==32561==    at 0x400543C: free (vg_replace_malloc.c:323)
==32561==    by 0x7D817C: (within /usr/lib/libfreetype.so.6.3.16)
==32561==    by 0x7DB9E9: ft_mem_free (in /usr/lib/libfreetype.so.6.3.16)
==32561==    by 0x7DC84E: FT_Remove_Module (in /usr/lib/libfreetype.so.6.3.16)
==32561==    by 0x7DCB3F: FT_Done_Library (in /usr/lib/libfreetype.so.6.3.16)
==32561==    by 0x7D8447: FT_Done_FreeType (in /usr/lib/libfreetype.so.6.3.16)
==32561==    by 0x40233BD: TTF_Quit (in /usr/lib/libSDL_ttf-2.0.so.0.6.3)
==32561==    by 0x805EF7E: Greebles::ShutdownSDL() (Main.cpp:237)
==32561==    by 0x805F855: Greebles::Shutdown() (Main.cpp:188)
==32561==    by 0x8060B74: main (Main.cpp:72)
==32561== 
==32561== ERROR SUMMARY: 12 errors from 3 contexts (suppressed: 262 from 2)
==32561== malloc/free: in use at exit: 8,620,832 bytes in 1,270 blocks.
==32561== malloc/free: 12,642 allocs, 11,372 frees, 35,625,357 bytes allocated.
==32561== For counts of detected errors, rerun with: -v
==32561== searching for pointers to 1,270 not-freed blocks.
==32561== checked 8,236,084 bytes.
==32561== 
==32561== 
==32561== 112 (8 direct, 104 indirect) bytes in 1 blocks are definitely lost in loss record 11 of 66
==32561==    at 0x400596E: realloc (vg_replace_malloc.c:429)
==32561==    by 0x2AF8B83: (within /usr/lib/libX11.so.6.2.0)
==32561==    by 0x2AF971B: (within /usr/lib/libX11.so.6.2.0)
==32561==    by 0x2AFB677: _XlcCreateLC (in /usr/lib/libX11.so.6.2.0)
==32561==    by 0x2B19AFA: _XlcDefaultLoader (in /usr/lib/libX11.so.6.2.0)
==32561==    by 0x2B01FD2: _XOpenLC (in /usr/lib/libX11.so.6.2.0)
==32561==    by 0x2B02112: _XlcCurrentLC (in /usr/lib/libX11.so.6.2.0)
==32561==    by 0x2B025C0: XSetLocaleModifiers (in /usr/lib/libX11.so.6.2.0)
==32561==    by 0x2135A8D: (within /usr/lib/libSDL-1.2.so.0.11.2)
==32561==    by 0x213F731: (within /usr/lib/libSDL-1.2.so.0.11.2)
==32561==    by 0x2140704: (within /usr/lib/libSDL-1.2.so.0.11.2)
==32561==    by 0x212A33D: SDL_VideoInit (in /usr/lib/libSDL-1.2.so.0.11.2)
==32561== 
==32561== 
==32561== 18 bytes in 2 blocks are definitely lost in loss record 16 of 66
==32561==    at 0x4005898: malloc (vg_replace_malloc.c:207)
==32561==    by 0x2B05882: (within /usr/lib/libX11.so.6.2.0)
==32561==    by 0x2B040D6: (within /usr/lib/libX11.so.6.2.0)
==32561==    by 0x2B05063: _XimSetICValueData (in /usr/lib/libX11.so.6.2.0)
==32561==    by 0x2B0B0D0: _XimLocalCreateIC (in /usr/lib/libX11.so.6.2.0)
==32561==    by 0x2AF2D7B: XCreateIC (in /usr/lib/libX11.so.6.2.0)
==32561==    by 0x213F589: (within /usr/lib/libSDL-1.2.so.0.11.2)
==32561==    by 0x2140704: (within /usr/lib/libSDL-1.2.so.0.11.2)
==32561==    by 0x212A33D: SDL_VideoInit (in /usr/lib/libSDL-1.2.so.0.11.2)
==32561==    by 0x20FE970: SDL_InitSubSystem (in /usr/lib/libSDL-1.2.so.0.11.2)
==32561==    by 0x20FE9B6: SDL_Init (in /usr/lib/libSDL-1.2.so.0.11.2)
==32561==    by 0x805EF98: Greebles::InitializeSDL() (Main.cpp:200)
==32561== 
==32561== 
==32561== 42 bytes in 2 blocks are definitely lost in loss record 24 of 66
==32561==    at 0x4005898: malloc (vg_replace_malloc.c:207)
==32561==    by 0x732ADA: ???
==32561==    by 0x72F074: ???
==32561==    by 0x21330CE: (within /usr/lib/libSDL-1.2.so.0.11.2)
==32561==    by 0x20FF42D: SDL_AudioInit (in /usr/lib/libSDL-1.2.so.0.11.2)
==32561==    by 0x20FE8CE: SDL_InitSubSystem (in /usr/lib/libSDL-1.2.so.0.11.2)
==32561==    by 0x20FFD84: SDL_OpenAudio (in /usr/lib/libSDL-1.2.so.0.11.2)
==32561==    by 0x605A5B: Mix_OpenAudio (in /usr/lib/libSDL_mixer-1.2.so.0.2.6)
==32561==    by 0x805F0E4: Greebles::InitializeSDL() (Main.cpp:212)
==32561==    by 0x805FA2D: Greebles::Init() (Main.cpp:123)
==32561==    by 0x80609CE: main (Main.cpp:21)
==32561== 
==32561== 
==32561== 80 bytes in 2 blocks are definitely lost in loss record 26 of 66
==32561==    at 0x4005898: malloc (vg_replace_malloc.c:207)
==32561==    by 0x732A3F: ???
==32561==    by 0x732AC5: ???
==32561==    by 0x72F074: ???
==32561==    by 0x21330CE: (within /usr/lib/libSDL-1.2.so.0.11.2)
==32561==    by 0x20FF42D: SDL_AudioInit (in /usr/lib/libSDL-1.2.so.0.11.2)
==32561==    by 0x20FE8CE: SDL_InitSubSystem (in /usr/lib/libSDL-1.2.so.0.11.2)
==32561==    by 0x20FFD84: SDL_OpenAudio (in /usr/lib/libSDL-1.2.so.0.11.2)
==32561==    by 0x605A5B: Mix_OpenAudio (in /usr/lib/libSDL_mixer-1.2.so.0.2.6)
==32561==    by 0x805F0E4: Greebles::InitializeSDL() (Main.cpp:212)
==32561==    by 0x805FA2D: Greebles::Init() (Main.cpp:123)
==32561==    by 0x80609CE: main (Main.cpp:21)
==32561== 
==32561== 
==32561== 1,024 bytes in 1 blocks are possibly lost in loss record 49 of 66
==32561==    at 0x4005898: malloc (vg_replace_malloc.c:207)
==32561==    by 0x2126285: (within /usr/lib/libSDL-1.2.so.0.11.2)
==32561==    by 0x2127EA5: SDL_CreateRGBSurface (in /usr/lib/libSDL-1.2.so.0.11.2)
==32561==    by 0x5C1D15: IMG_LoadPNG_RW (in /usr/lib/libSDL_image-1.2.so.0.1.5)
==32561==    by 0x5BDD6C: IMG_LoadTyped_RW (in /usr/lib/libSDL_image-1.2.so.0.1.5)
==32561==    by 0x5BDE90: IMG_Load (in /usr/lib/libSDL_image-1.2.so.0.1.5)
==32561==    by 0x807F81F: Framework::Graphics::Image::Image(std::string const&, unsigned, bool) (Graphics.cpp:55)
==32561==    by 0x805C47A: Greebles::LoadImages() (Main.cpp:313)
==32561==    by 0x805FDDC: Greebles::Init() (Main.cpp:143)
==32561==    by 0x80609CE: main (Main.cpp:21)
==32561== 
==32561== 
==32561== 1,057,892 (1,980 direct, 1,055,912 indirect) bytes in 33 blocks are definitely lost in loss record 62 of 66
==32561==    at 0x4005898: malloc (vg_replace_malloc.c:207)
==32561==    by 0x2127E2B: SDL_CreateRGBSurface (in /usr/lib/libSDL-1.2.so.0.11.2)
==32561==    by 0x5C1D15: IMG_LoadPNG_RW (in /usr/lib/libSDL_image-1.2.so.0.1.5)
==32561==    by 0x5BDD6C: IMG_LoadTyped_RW (in /usr/lib/libSDL_image-1.2.so.0.1.5)
==32561==    by 0x5BDE90: IMG_Load (in /usr/lib/libSDL_image-1.2.so.0.1.5)
==32561==    by 0x807F81F: Framework::Graphics::Image::Image(std::string const&, unsigned, bool) (Graphics.cpp:55)
==32561==    by 0x805AEA5: Greebles::LoadImages() (Main.cpp:293)
==32561==    by 0x805FDDC: Greebles::Init() (Main.cpp:143)
==32561==    by 0x80609CE: main (Main.cpp:21)
==32561== 
==32561== 
==32561== 7,481,552 bytes in 20 blocks are possibly lost in loss record 66 of 66
==32561==    at 0x4005898: malloc (vg_replace_malloc.c:207)
==32561==    by 0x2127FD3: SDL_CreateRGBSurface (in /usr/lib/libSDL-1.2.so.0.11.2)
==32561==    by 0x5C1D15: IMG_LoadPNG_RW (in /usr/lib/libSDL_image-1.2.so.0.1.5)
==32561==    by 0x5BDD6C: IMG_LoadTyped_RW (in /usr/lib/libSDL_image-1.2.so.0.1.5)
==32561==    by 0x5BDE90: IMG_Load (in /usr/lib/libSDL_image-1.2.so.0.1.5)
==32561==    by 0x807F81F: Framework::Graphics::Image::Image(std::string const&, unsigned, bool) (Graphics.cpp:55)
==32561==    by 0x805AEA5: Greebles::LoadImages() (Main.cpp:293)
==32561==    by 0x805FDDC: Greebles::Init() (Main.cpp:143)
==32561==    by 0x80609CE: main (Main.cpp:21)
==32561== 
==32561== LEAK SUMMARY:
==32561==    definitely lost: 2,128 bytes in 40 blocks.
==32561==    indirectly lost: 1,056,016 bytes in 160 blocks.
==32561==      possibly lost: 7,482,576 bytes in 21 blocks.
==32561==    still reachable: 80,112 bytes in 1,049 blocks.
==32561==         suppressed: 0 bytes in 0 blocks.
==32561== Reachable blocks (those to which a pointer was found) are not shown.
==32561== To see them, rerun with: --leak-check=full --show-reachable=yes


Can anyone help me understand which (if any) of these are leaks from SDL or some other library and not my own code? I'll be happy to provide any other necessary info, right now I am totally clueless. Thanks, Svenjamin

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this