Почему в моем простом приложении GLX происходит утечка памяти?

В приведенном ниже коде показана небольшая 48-байтовая утечка в valgrind.

#include <X11/Xlib.h>
#include <GL/glx.h>
#include <unistd.h>

int main( int argc, char* argv[] )
{
    Display* _display;
    Window _windowHandle;
    XVisualInfo* _visual;
    GLXContext _context;
    Atom _deleteWindowMessage;
    Atom _pingWindowMessage;

    _display = XOpenDisplay( NULL );

    int attributes[] = { GLX_RGBA,
                         GLX_DOUBLEBUFFER,
                         GLX_RED_SIZE, 8,
                         GLX_BLUE_SIZE, 8,
                         GLX_GREEN_SIZE, 8,
                         GLX_ALPHA_SIZE, 8,
                         GLX_DEPTH_SIZE, 8,
                         GLX_STENCIL_SIZE, 0,
                         0 };

    _visual = glXChooseVisual( _display, 
                               DefaultScreen( _display ),
                               attributes );

    _context = glXCreateContext( _display,
                                 _visual,
                                 0,
                                 GL_TRUE );

    Colormap colormap;

    colormap = XCreateColormap( _display, 
                                RootWindow( _display, _visual->screen ),
                                _visual->visual,
                                AllocNone );

    XSetWindowAttributes windowAttributes;

    windowAttributes.colormap = colormap;
    windowAttributes.border_pixel = 0;
    windowAttributes.event_mask = ExposureMask | StructureNotifyMask;


    _windowHandle = 
        XCreateWindow( _display,
                       RootWindow( _display, _visual->screen ),
                           0, 
                           0,
                           1280, 
                           720,
                           0,                      // Borderwidth
                           _visual->depth,         // Depth
                           InputOutput,
                           _visual->visual,
                           CWBorderPixel | CWColormap | CWEventMask,
                           &windowAttributes );
    XFreeColormap( _display, colormap );


    XMapWindow( _display, _windowHandle );

    // causes 48 byte leak...
    glXMakeCurrent( _display,
                    _windowHandle,
                    _context );

    sleep( 3 );

    XUnmapWindow( _display, _windowHandle );


    XDestroyWindow( _display, _windowHandle );


    glXMakeCurrent( _display, 
                    None,
                    NULL );

    glXDestroyContext( _display, _context );

    XFree( _visual );

    XCloseDisplay( _display );

    return 0;
}

Все, что делает этот код, — это инициализирует окно для рендеринга GLX, а затем удаляет его. Забавно то, что как только я вызываю glXMakeCurrent(), происходит утечка 48 байт... Вывод valgrind выглядит так:

[developer@localhost ~]$ valgrind --tool=memcheck --leak-check=full ./simplex
==9531== Memcheck, a memory error detector
==9531== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==9531== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info
==9531== Command: ./simplex
==9531== 
==9531== 
==9531== HEAP SUMMARY:
==9531==     in use at exit: 248 bytes in 6 blocks
==9531==   total heap usage: 1,265 allocs, 1,259 frees, 2,581,764 bytes allocated
==9531== 
==9531== 48 bytes in 1 blocks are definitely lost in loss record 5 of 6
==9531==    at 0x400591C: malloc (vg_replace_malloc.c:195)
==9531==    by 0x349D0F8: ??? (in /usr/lib/nvidia/libGL.so.180.60)
==9531== 
==9531== LEAK SUMMARY:
==9531==    definitely lost: 48 bytes in 1 blocks
==9531==    indirectly lost: 0 bytes in 0 blocks
==9531==      possibly lost: 0 bytes in 0 blocks
==9531==    still reachable: 200 bytes in 5 blocks
==9531==         suppressed: 0 bytes in 0 blocks
==9531== Reachable blocks (those to which a pointer was found) are not shown.
==9531== To see them, rerun with: --leak-check=full --show-reachable=yes
==9531== 
==9531== For counts of detected and suppressed errors, rerun with: -v
==9531== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 30 from 8)

Если вы закомментируете вызов glXMakeCurrent() прямо перед сном, утечка исчезнет... Конечно, мне нужно сделать этот вызов, чтобы что-то отрендерить!

Настоящая проблема заключается в том, что мое приложение создает много дочерних окон, каждое из которых связано с контекстом GLX... и каждое пропускает те же самые 48 байтов... Я не знаю, что еще попробовать (код очищает контекст GLX). .. Любые идеи?


person dicroce    schedule 14.11.2009    source источник


Ответы (1)


Хорошо, похоже, что он действительно не течет.

Valgrind все еще сообщает об утечке, но я написал тестовое приложение, которое вызывает тысячи окон в случайных местах, а память полностью плоская через top... Итак, похоже, мне понадобится файл подавления для glx-приложений.

person dicroce    schedule 15.11.2009