Tag: valgrind

Mac OS X上的Valgrind错误对于printf来说是双倍的

目前,我正在学习C语言,这是一个很棒的学习代码 。 我遇到了以下情况: 我编译以下代码,一切对我来说都很好: #include int main(int argc, char *argv[]) { int bugs = 100; double bug_rate = 1.2; printf(“You have %d bugs a the imaginary rate of %f!\n”, bugs, bug_rate); return 0; } 它也正常工作。 当我现在运行Valgrind(3.11.0; 应该更新为OS X El Capitan )时,我得到以下消息: ==18896== Memcheck, a memory error detector ==18896== Copyright (C) 2002-2015, and GNU GPL’d, by […]

为什么pthread导致内存泄漏

每当我创建一个pthread时,valgrind就会输出内存泄漏, 例如下面的代码: #include #include #include void *timer1_function (void *eit){ (void) eit; printf(“hello world\n”); pthread_exit(NULL); } int main(void){ pthread_t timer1; pthread_create( &timer1, NULL, timer1_function, NULL); ///////line13 int i=0; for(i=0;i<2;i++){usleep(1);} return 0; } valgrind输出 ==1395== HEAP SUMMARY: ==1395== in use at exit: 136 bytes in 1 blocks ==1395== total heap usage: 6 allocs, 5 frees, 1,134 bytes […]

Valgrind在使用glib数据类型时报告内存“可能已丢失”

我正在使用许多glib数据结构(GHashTable,GSList等)开发一个库。 我一直在使用valgrind经常检查我的代码是否有内存泄漏。 valgrind指出的大多数问题很容易解决,但有一些我无法弄清楚。 所有这些都被报道为“可能丢失”。 在valgrind stacktrace的顶部,我总能找到相同的4个库: ==29997== 1,512 bytes in 3 blocks are possibly lost in loss record 24 of 25 ==29997== at 0x4004B11: memalign (vg_replace_malloc.c:532) ==29997== by 0x4004B6B: posix_memalign (vg_replace_malloc.c:660) ==29997== by 0x5E9AC4: ??? (in /lib/libglib-2.0.so.0.1200.3) ==29997== by 0x5EA4FE: g_slice_alloc (in /lib/libglib-2.0.so.0.1200.3) 在调用堆栈中,总是调用glib函数,例如g_key_file_new(),g_slist_prepend(),g_strsplit(),g_key_file_load_from_file(),g_file_get_contents()。 我的问题是: 有没有人遇到这个并找到了解决方法? 或者这是我可以忽略的东西? 是否由于glib使用内存池,如此处所示 ? 我在用 的valgrind-3.5.0 巧舌如簧-2.12.3 gcc(GCC)4.1.2 20080704(Red Hat […]

有关动态代码分析的任何参考?

昨天我正在阅读有关调试技​​术的文章,发现Valgrind非常有趣。 它似乎使用动态代码分析技术。 我跟着从原始引用到其他名为Path Profiling的链接 。 我试过谷歌搜索,但我想我使用错误的术语来搜索这些概念的一个很好的参考。 有人建议一个好的资源考虑到我没有编译器和编程语言的背景吗?

Valgrind显示printf和未使用的块的内存泄漏

#include #include #include int main(int argc, char *argv[]){ char *str = malloc(sizeof(char)*5); str = strcpy(str, “test”); printf(“%s\n”, str); free(str); return 0; } 当我在Mac上使用Valgrind(OS X,10.9.5)时,我收到以下消息: ==77215== HEAP SUMMARY: ==77215== in use at exit: 29,211 bytes in 374 blocks ==77215== total heap usage: 451 allocs, 77 frees, 35,160 bytes allocated ==77215== ==77215== 4,096 bytes in 1 blocks […]

GTK hello_world计划中的内存泄漏

所以…我正试图消除我的GTK + 3程序中的一些内存泄漏。 我虽然回顾一些简单的例子看看是否有一些我忘记的清理工具是个好主意,但文档中提供的hello_world程序也有漏洞。 (下面的Valgrind输出)。 这些泄漏是否可以接受? 如果是这样,我应该使用其他一些应用来调试GTK程序吗? ==13717== Memcheck, a memory error detector ==13717== Copyright (C) 2002-2012, and GNU GPL’d, by Julian Seward et al. ==13717== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info ==13717== Command: ./a ==13717== Hello World ==13717== ==13717== HEAP SUMMARY: ==13717== in use at exit: 1,578,162 bytes in 11,614 […]

OSX El Capitan中可能的内存泄漏Valgrind

我收到一个possibly lost: 2,064 bytes in 1 blocks的警告possibly lost: 2,064 bytes in 1 blocks在OSX Yosemite上使用Valgrind时possibly lost: 2,064 bytes in 1 blocks 。 有没有解决这个问题? 我用brew安装了valgrind。 以下是如何重现的示例 ~/cat hello.c int main() { return 123; } ~/uname -a Darwin mac.local 15.2.0 Darwin Kernel Version 15.2.0: Fri Nov 13 19:56:56 PST 2015; root:xnu-3248.20.55~2/RELEASE_X86_64 x86_64 i386 MacBookAir6,2 Darwin ~/clang –version Apple […]

抑制泄漏对Valgrind意味着什么?

我在文件fifo.h和fifo.c开发了一个FIFO列表(队列)的纯C实现,并编写了一个测试程序testfifo.c ,我将其编译为./bin/testfifo 。 节点结构在list.h定义。 我在OS X 10.6上通过Valgrind运行我的程序 valgrind –tool=memcheck –leak-check=full –show-reachable=yes ./bin/testfifo 并获得以下输出 ==54688== Memcheck, a memory error detector ==54688== Copyright (C) 2002-2011, and GNU GPL’d, by Julian Seward et al. ==54688== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info ==54688== Command: bin/testfifo ==54688== –54688– bin/testfifo: –54688– dSYM directory is missing; consider using […]

Valgrind报告了一个非常简单的C程序的错误

我正在从Learn C The Hard Way学习C语言。 我正在练习6 ,虽然我可以使它工作,但valgrind会报告很多错误。 这是从文件ex6.c删除的最小程序: #include int main(int argc, char *argv[]) { char initial = ‘A’; float power = 2.345f; printf(“Character is %c.\n”, initial); printf(“You have %f levels of power.\n”, power); return 0; } Makefile内容只是CFLAGS=-Wall -g 。 我使用$ make ex6编译程序(没有编译器警告或错误)。 使用$ ./ex6执行会产生预期的输出。 当我用$ valgrind ./ex6运行程序时,我得到的错误是我无法解决的。 这是完整的输出: ==69691== Memcheck, a memory error detector […]