简体   繁体   中英

c++ Allegro 5 - memory leaks (valgrind)

I try to write simple game with allegro.cc library and at the beginning I have memory leaks found by valgrind. Could anyone tell me what do I wrong? I don't believe that the allegro has memory leaks. The code:

#include <stdio.h>
#include <stdlib.h>
#include <allegro5/allegro.h>

int main(int argc, char** argv)
{
    printf("start\n");

    if (!al_init()) 
        exit(EXIT_FAILURE);

    ALLEGRO_DISPLAY *display = al_create_display(100, 100);
    if (display == NULL) 
        exit(EXIT_FAILURE);

    al_destroy_display(display);
    al_uninstall_system();

    return EXIT_SUCCESS;
}

I run it on Linux Ubuntu 16.04.

Command to compile the code: gcc -Wall test.c -o test.o $(pkg-config --libs allegro-5)

Command to run valgrind: valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./test.o

Valgrind logs:

LEAK SUMMARY:
==28629==    definitely lost: 88 bytes in 2 blocks
==28629==    indirectly lost: 2,668 bytes in 10 blocks
==28629==      possibly lost: 0 bytes in 0 blocks
==28629==    still reachable: 121,860 bytes in 675 blocks
==28629==         suppressed: 0 bytes in 0 blocks
==28629== Reachable blocks (those to which a pointer was found) are not shown.
==28629== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==28629==
==28629== For counts of detected and suppressed errors, rerun with: -v
==28629== ERROR SUMMARY: 388 errors from 325 contexts (suppressed: 0 from 0)

valgrind is reporting 160 lost bytes in 2 blocks. One is 32 bytes, the other is 128 directly lost. This is on Ubuntu 18.04 with Allegro 5.2.5. You can see them below :

The memory is reported as being leaked by allegro, but it may be nothing. I'll look into it. There's nothing wrong with your own code, so don't worry about memory leaks at the moment.

==23579== 32 bytes in 1 blocks are definitely lost in loss record 386 of 1,647
==23579==    at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==23579==    by 0x11B596A1: ??? (in /usr/lib/x86_64-linux-gnu/libGLX_mesa.so.0.0.0)
==23579==    by 0x67DBA07: glXCreateWindow (in /usr/lib/x86_64-linux-gnu/libGLX.so.0.0.0)
==23579==    by 0x4F49B18: _al_xglx_config_create_context (xglx_config.c:572)
==23579==    by 0x4F4328F: xdpy_create_display_locked (xdisplay.c:464)
==23579==    by 0x4F43A57: xdpy_create_display (xdisplay.c:614)
==23579==    by 0x4EB5D1D: al_create_display (display.c:53)
==23579==    by 0x108978: main (gtktest.c:17)


==23579== 1,960 (128 direct, 1,832 indirect) bytes in 1 blocks are definitely lost in loss record 1,626 of 1,647
==23579==    at 0x4C31B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==23579==    by 0x11B7C93A: ??? (in /usr/lib/x86_64-linux-gnu/libGLX_mesa.so.0.0.0)
==23579==    by 0x11B59171: ??? (in /usr/lib/x86_64-linux-gnu/libGLX_mesa.so.0.0.0)
==23579==    by 0x11B5977C: ??? (in /usr/lib/x86_64-linux-gnu/libGLX_mesa.so.0.0.0)
==23579==    by 0x67DBA07: glXCreateWindow (in /usr/lib/x86_64-linux-gnu/libGLX.so.0.0.0)
==23579==    by 0x4F49B18: _al_xglx_config_create_context (xglx_config.c:572)
==23579==    by 0x4F4328F: xdpy_create_display_locked (xdisplay.c:464)
==23579==    by 0x4F43A57: xdpy_create_display (xdisplay.c:614)
==23579==    by 0x4EB5D1D: al_create_display (display.c:53)
==23579==    by 0x108978: main (gtktest.c:17)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM