LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Valgrind and leaks in Xlib (https://www.linuxquestions.org/questions/programming-9/valgrind-and-leaks-in-xlib-927766/)

King_DuckZ 02-05-2012 11:54 AM

Valgrind and leaks in Xlib
 
Hello, I'm velgrinding my program to check for errors and I corrected a few. My problem is that I still have a number of leaks being reported. I'm no valgrind expert, but it looks as if they come from Xlib. Can somebody give me his advice please? Is there really a leak and should I report it?

Code:

==9446== HEAP SUMMARY:
==9446==    in use at exit: 27,628 bytes in 394 blocks
==9446==  total heap usage: 4,572 allocs, 4,178 frees, 7,535,764 bytes allocated
==9446==
==9446== 2 bytes in 1 blocks are still reachable in loss record 1 of 59
==9446==    at 0x4C28E8D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==9446==    by 0x5D1E9CD: _XlcCreateLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D3C1DF: _XlcDefaultLoader (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D25D85: _XOpenLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D25EC7: _XlcCurrentLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D59AD4: _XkbGetCharset (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D580AC: XkbTranslateKeySym (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D58309: XLookupString (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x4E3A41F: duckcore::CEventManager::DoEvents() const (EventManager.cpp:44)
==9446==    by 0x40A83E: duckgame::CApp::DoEvents() const (App.cpp:122)
==9446==    by 0x40CC65: main (main.cpp:61)
==9446==
==9446== 2 bytes in 1 blocks are still reachable in loss record 2 of 59
==9446==    at 0x4C28E8D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==9446==    by 0x73C1091: strdup (in /lib64/libc-2.13.so)
==9446==    by 0x5D1B70B: _XlcResolveLocaleName (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D1EBE6: ??? (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D1E172: ??? (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D1E985: _XlcCreateLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D3C1DF: _XlcDefaultLoader (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D25D85: _XOpenLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D25EC7: _XlcCurrentLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D59AD4: _XkbGetCharset (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D580AC: XkbTranslateKeySym (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D58309: XLookupString (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x4E3A41F: duckcore::CEventManager::DoEvents() const (EventManager.cpp:44)
==9446==    by 0x40A83E: duckgame::CApp::DoEvents() const (App.cpp:122)
==9446==    by 0x40CC65: main (main.cpp:61)
==9446==
==9446== 7 bytes in 1 blocks are still reachable in loss record 3 of 59
==9446==    at 0x4C28E8D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==9446==    by 0x73C1091: strdup (in /lib64/libc-2.13.so)
==9446==    by 0x5D1ED4E: ??? (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D1E172: ??? (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D1E985: _XlcCreateLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D3C1DF: _XlcDefaultLoader (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D25D85: _XOpenLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D25EC7: _XlcCurrentLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D59AD4: _XkbGetCharset (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D580AC: XkbTranslateKeySym (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D58309: XLookupString (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x4E3A41F: duckcore::CEventManager::DoEvents() const (EventManager.cpp:44)
==9446==    by 0x40A83E: duckgame::CApp::DoEvents() const (App.cpp:122)
==9446==    by 0x40CC65: main (main.cpp:61)
==9446==
==9446== 16 bytes in 1 blocks are still reachable in loss record 4 of 59
==9446==    at 0x4C28E8D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==9446==    by 0x5D25C39: _XlcAddLoader (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D1E1A1: _XlcInitLoader (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D25D60: _XOpenLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D25EC7: _XlcCurrentLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D59AD4: _XkbGetCharset (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D580AC: XkbTranslateKeySym (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D58309: XLookupString (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x4E3A41F: duckcore::CEventManager::DoEvents() const (EventManager.cpp:44)
==9446==    by 0x40A83E: duckgame::CApp::DoEvents() const (App.cpp:122)
==9446==    by 0x40CC65: main (main.cpp:61)
==9446==
==9446== 16 bytes in 1 blocks are still reachable in loss record 5 of 59
==9446==    at 0x4C28E8D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==9446==    by 0x5D25C39: _XlcAddLoader (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D1E1AF: _XlcInitLoader (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D25D60: _XOpenLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D25EC7: _XlcCurrentLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D59AD4: _XkbGetCharset (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D580AC: XkbTranslateKeySym (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D58309: XLookupString (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x4E3A41F: duckcore::CEventManager::DoEvents() const (EventManager.cpp:44)
==9446==    by 0x40A83E: duckgame::CApp::DoEvents() const (App.cpp:122)
==9446==    by 0x40CC65: main (main.cpp:61)
==9446==
==9446== 16 bytes in 1 blocks are still reachable in loss record 6 of 59
==9446==    at 0x4C28E8D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==9446==    by 0x5D25C39: _XlcAddLoader (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D25D60: _XOpenLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D25EC7: _XlcCurrentLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D59AD4: _XkbGetCharset (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D580AC: XkbTranslateKeySym (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D58309: XLookupString (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x4E3A41F: duckcore::CEventManager::DoEvents() const (EventManager.cpp:44)
==9446==    by 0x40A83E: duckgame::CApp::DoEvents() const (App.cpp:122)
==9446==    by 0x40CC65: main (main.cpp:61)
==9446==
==9446== 16 bytes in 1 blocks are still reachable in loss record 7 of 59
==9446==    at 0x4C28F72: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==9446==    by 0x5D1C5CB: ??? (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D1CA78: ??? (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D1E180: ??? (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D1E985: _XlcCreateLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D3C1DF: _XlcDefaultLoader (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D25D85: _XOpenLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D25EC7: _XlcCurrentLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D59AD4: _XkbGetCharset (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D580AC: XkbTranslateKeySym (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D58309: XLookupString (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x4E3A41F: duckcore::CEventManager::DoEvents() const (EventManager.cpp:44)
==9446==    by 0x40A83E: duckgame::CApp::DoEvents() const (App.cpp:122)
==9446==    by 0x40CC65: main (main.cpp:61)
==9446==
==9446== 16 bytes in 2 blocks are still reachable in loss record 8 of 59
==9446==    at 0x4C28E8D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==9446==    by 0x5D1D021: ??? (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D1E180: ??? (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D1E985: _XlcCreateLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D3C1DF: _XlcDefaultLoader (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D25D85: _XOpenLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D25EC7: _XlcCurrentLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D59AD4: _XkbGetCharset (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D580AC: XkbTranslateKeySym (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D58309: XLookupString (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x4E3A41F: duckcore::CEventManager::DoEvents() const (EventManager.cpp:44)
==9446==    by 0x40A83E: duckgame::CApp::DoEvents() const (App.cpp:122)
==9446==    by 0x40CC65: main (main.cpp:61)
==9446==
==9446== 24 bytes in 1 blocks are still reachable in loss record 9 of 59
==9446==    at 0x4C28E8D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==9446==    by 0xA622168: XauFileName (in /usr/lib64/libXau.so.6.0.0)
==9446==    by 0xA6223D6: XauGetBestAuthByAddr (in /usr/lib64/libXau.so.6.0.0)
==9446==    by 0x7AFBE59: ??? (in /usr/lib64/libxcb.so.1.1.0)
==9446==    by 0x7AFC15B: ??? (in /usr/lib64/libxcb.so.1.1.0)
==9446==    by 0x7AFBB08: xcb_connect_to_display_with_auth_info (in /usr/lib64/libxcb.so.1.1.0)
==9446==    by 0x5D09151: _XConnectXCB (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5CF8600: XOpenDisplay (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x625A8F2: duckgraphic::CWindowMakerX::CWinCreator::CreateDisplay() (WindowMakerX.cpp:32)
==9446==    by 0x625AB89: duckgraphic::CWindowMakerX::CWindowMakerX(duckmem::CFixedSizeArray<unsigned int, 2ul> const&) (WindowMakerX.cpp:91)
==9446==    by 0x40A219: duckgame::CApp::CLocalData::CLocalData() (App.cpp:41)
==9446==    by 0x40AD2B: Loki::Pimpl<duckgame::CApp::CLocalData, Loki::ConstPropPtr<duckgame::CApp::CLocalData> >::Pimpl() (Pimpl.h:81)
==9446==    by 0x40A30A: duckgame::CApp::CApp(std::string const&, std::string const&, std::vector<std::string, std::allocator<std::string> > const&) (App.cpp:49)
==9446==    by 0x40CBB3: main (main.cpp:45)
==9446==
==9446== 24 bytes in 1 blocks are still reachable in loss record 10 of 59
==9446==    at 0x4C28E8D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==9446==    by 0x60124AD: XextCreateExtension (in /usr/lib64/libXext.so.6.4.0)
==9446==    by 0x66FB4A1: ??? (in /usr/lib64/opengl/nvidia/lib/libGL.so.290.10)
==9446==    by 0x1D: ???
==9446==    by 0x4064627: ???
==9446==    by 0x7DBE032E: ???
==9446==    by 0x400933A: do_lookup_x (in /lib64/ld-2.13.so)
==9446==    by 0x40096D2: _dl_lookup_symbol_x (in /lib64/ld-2.13.so)
==9446==    by 0x400CF23: _dl_fixup (in /lib64/ld-2.13.so)
==9446==    by 0x66F20BD: ??? (in /usr/lib64/opengl/nvidia/lib/libGL.so.290.10)
==9446==    by 0x10000000B: ???
==9446==    by 0x60000800F: ???
==9446==    by 0x100000004: ???
==9446==    by 0x6FFFFFFFF: ???
==9446==    by 0x625CECB: Loki::Pimpl<duckgraphic::COpenGLContext::LOCAL_DATA, Loki::ConstPropPtr<duckgraphic::COpenGLContext::LOCAL_DATA> >::operator->() (Pimpl.h:99)
==9446==
==9446== 24 bytes in 1 blocks are still reachable in loss record 11 of 59
==9446==    at 0x4C28E8D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==9446==    by 0x60124AD: XextCreateExtension (in /usr/lib64/libXext.so.6.4.0)
==9446==    by 0x6011F44: ??? (in /usr/lib64/libXext.so.6.4.0)
==9446==    by 0x60122BC: ??? (in /usr/lib64/libXext.so.6.4.0)
==9446==    by 0x60126E1: XextAddDisplay (in /usr/lib64/libXext.so.6.4.0)
==9446==    by 0x66FBC9A: ??? (in /usr/lib64/opengl/nvidia/lib/libGL.so.290.10)
==9446==    by 0x1D: ???
==9446==    by 0x4064627: ???
==9446==    by 0x7DBE032E: ???
==9446==    by 0x400933A: do_lookup_x (in /lib64/ld-2.13.so)
==9446==    by 0x40096D2: _dl_lookup_symbol_x (in /lib64/ld-2.13.so)
==9446==    by 0x400CF23: _dl_fixup (in /lib64/ld-2.13.so)
==9446==    by 0x66F20BD: ??? (in /usr/lib64/opengl/nvidia/lib/libGL.so.290.10)
==9446==    by 0x10000000B: ???
==9446==    by 0x60000800F: ???
==9446==    by 0x100000004: ???
==9446==    by 0x6FFFFFFFF: ???
==9446==    by 0x625CECB: Loki::Pimpl<duckgraphic::COpenGLContext::LOCAL_DATA, Loki::ConstPropPtr<duckgraphic::COpenGLContext::LOCAL_DATA> >::operator->() (Pimpl.h:99)
==9446==
==9446== 24 bytes in 1 blocks are still reachable in loss record 12 of 59
==9446==    at 0x4C27574: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==9446==    by 0x5D1C1A7: ??? (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D1E963: _XlcCreateLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D3C1DF: _XlcDefaultLoader (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D25D85: _XOpenLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D25EC7: _XlcCurrentLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D59AD4: _XkbGetCharset (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D580AC: XkbTranslateKeySym (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D58309: XLookupString (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x4E3A41F: duckcore::CEventManager::DoEvents() const (EventManager.cpp:44)
==9446==    by 0x40A83E: duckgame::CApp::DoEvents() const (App.cpp:122)
==9446==    by 0x40CC65: main (main.cpp:61)
==9446==
==9446== 24 bytes in 1 blocks are still reachable in loss record 13 of 59
==9446==    at 0x4C28E8D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==9446==    by 0x5D25D97: _XOpenLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D25EC7: _XlcCurrentLC (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D59AD4: _XkbGetCharset (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D580AC: XkbTranslateKeySym (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x5D58309: XLookupString (in /usr/lib64/libX11.so.6.3.0)
==9446==    by 0x4E3A41F: duckcore::CEventManager::DoEvents() const (EventManager.cpp:44)
==9446==    by 0x40A83E: duckgame::CApp::DoEvents() const (App.cpp:122)
==9446==    by 0x40CC65: main (main.cpp:61)
==9446==
==9446== 32 bytes in 1 blocks are still reachable in loss record 14 of 59
==9446==    at 0x4C27574: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==9446==    by 0x7D0E52F: _dlerror_run (in /lib64/libdl-2.13.so)
==9446==    by 0x7D0E099: dlsym (in /lib64/libdl-2.13.so)
==9446==    by 0x672289D: ??? (in /usr/lib64/opengl/nvidia/lib/libGL.so.290.10)
==9446==    by 0x695041F: ??? (in /usr/lib64/opengl/nvidia/lib/libGL.so.290.10)
==9446==    by 0x69800BF: ???
==9446==
==9446== 40 bytes in 1 blocks are still reachable in loss record 15 of 59
==9446==    at 0x4C28E8D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==9446==    by 0x400C118: _dl_map_object_deps (in /lib64/ld-2.13.so)
==9446==    by 0x40119C7: dl_open_worker (in /lib64/ld-2.13.so)
==9446==    by 0x400D915: _dl_catch_error (in /lib64/ld-2.13.so)
==9446==    by 0x4011509: _dl_open (in /lib64/ld-2.13.so)
==9446==    by 0x7D0DF25: dlopen_doit (in /lib64/libdl-2.13.so)
==9446==    by 0x400D915: _dl_catch_error (in /lib64/ld-2.13.so)
==9446==    by 0x7D0E4BE: _dlerror_run (in /lib64/libdl-2.13.so)
==9446==    by 0x7D0DFC0: dlopen@@GLIBC_2.2.5 (in /lib64/libdl-2.13.so)
==9446==    by 0x67228C2: ??? (in /usr/lib64/opengl/nvidia/lib/libGL.so.290.10)
==9446==    by 0x695041F: ??? (in /usr/lib64/opengl/nvidia/lib/libGL.so.290.10)
==9446==    by 0x69800BF: ???
==9446==

[CUT]

==9446==
==9446== LEAK SUMMARY:
==9446==    definitely lost: 124 bytes in 1 blocks
==9446==    indirectly lost: 0 bytes in 0 blocks
==9446==      possibly lost: 0 bytes in 0 blocks
==9446==    still reachable: 27,504 bytes in 393 blocks
==9446==        suppressed: 0 bytes in 0 blocks

As you see, most of the leaks are reported from within DoEvents(). Here is the code, in case it's needed:
Code:

        bool CEventManager::DoEvents() const {
                do {
                        XNextEvent(m_display, &m_event);
                        switch (m_event.type) {
                        case KeyPress:
                        {
                                KeySym keysym;
                                char buffer[1];
                                if ((XLookupString(reinterpret_cast<XKeyEvent*>(&m_event), buffer, 1, &keysym, NULL) == 1) and (keysym == static_cast<KeySym>(XK_Escape)))
                                        return false;
                                break;
                        }
                        }
                } while(XPending(m_display));
                return true;
        }


millgates 02-05-2012 12:21 PM

Yes, I also noticed that xlib, opengl, sdl and some other libraries generate a lot of errors in valgrind, especially if you use ATI drivers. It shouldn't be anything to worry about, probably just whoever coded these libraries just didn't bother freeing some memory that will be freed when the program exits anyway, or initializing some variables. I believe you can safely ignore most of them.


All times are GMT -5. The time now is 04:55 PM.