简体   繁体   English

C ++ Allegro 5-内存泄漏(Valgrind)

[英]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. 我尝试使用allegro.cc库编写简单的游戏,一开始我有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. 我在Linux Ubuntu 16.04上运行它。

Command to compile the code: gcc -Wall test.c -o test.o $(pkg-config --libs allegro-5) 编译代码的命令: 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的命令: valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./test.o

Valgrind logs: Valgrind日志:

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. valgrind报告2个块中160丢失的字节。 One is 32 bytes, the other is 128 directly lost. 一个是32字节,另一个是128个直接丢失的字节。 This is on Ubuntu 18.04 with Allegro 5.2.5. 这是在带有Allegro 5.2.5的Ubuntu 18.04上。 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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