【发布时间】:2019-07-02 00:42:05
【问题描述】:
我尝试使用 allegro.cc 库编写简单的游戏,一开始我发现了 valgrind 的内存泄漏。谁能告诉我我做错了什么?我不相信快板有内存泄漏。代码:
#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;
}
我在 Linux Ubuntu 16.04 上运行它。
编译代码的命令:gcc -Wall test.c -o test.o $(pkg-config --libs allegro-5)
运行 valgrind 的命令:valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./test.o
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)
【问题讨论】:
-
不相关,但按照惯例,
.o用于目标文件,而不是可执行文件。 -
乍一看,您的代码似乎没有泄漏任何内存。我会在 allegro 的论坛中更具体地要求这个
-
您有日志中泄漏的详细信息吗? -v 有什么作用吗?
标签: c gcc memory-leaks valgrind allegro5