Valgrind 正在报告 printf 和 put 等函数上仍可到达的“错误”。我真的不知道该怎么办。我需要摆脱它,因为这是一个学校项目,不能有任何错误。我该如何处理这个问题?从报告中我可以看到这些函数使用malloc
,但我一直以为他们自己处理内存,对吗?
我使用的是 mac OS X,所以也许这是 valgrind 和操作系统之间的问题?
示例代码:错误出现在使用的任何 put 或 printf 上
void twittear(array_t* array_tweets, hash_t* hash, queue_t* queue_input){
char* user = queue_see_first(queue_input);
char key[1] = "@";
if (!user || user[0] != key[0]) {
puts("ERROR_WRONG_COMAND");
return;
}
queue_t* queue_keys = queue_create();
char* text = join_text(queue_input, queue_keys);
if (!text) {
puts("ERROR_TWEET_TOO_LONG");
queue_destroy(queue_keys, NULL);
return;
}
int id = new_tweet(array_tweets, text);
while (!queue_is_empty(queue_keys))
hash_tweet(hash, queue_dequeue(queue_keys), id);
queue_destroy(queue_keys, NULL);
printf("OK %d\n", id);
}
ERROR:
==1954== 16,384 bytes in 1 blocks are still reachable in loss record 77 of 77
==1954== at 0x47E1: malloc (vg_replace_malloc.c:300)
==1954== by 0x183855: __smakebuf (in /usr/lib/system/libsystem_c.dylib)
==1954== by 0x198217: __swsetup (in /usr/lib/system/libsystem_c.dylib)
==1954== by 0x1B1158: __v2printf (in /usr/lib/system/libsystem_c.dylib)
==1954== by 0x1B16AF: __xvprintf (in /usr/lib/system/libsystem_c.dylib)
==1954== by 0x188B29: vfprintf_l (in /usr/lib/system/libsystem_c.dylib)
==1954== by 0x18696F: printf (in /usr/lib/system/libsystem_c.dylib)
==1954== by 0x1000036F3: twittear (main.c:138)
==1954== by 0x100003C8D: main (main.c:309
Valgrind 在 Mac OS X 上有些问题;它对某些系统库没有完全抑制。 (也就是说,它没有正确忽略一些“预期的”泄漏。)结果通常会包含一些像这样的虚假结果,以及由于函数优化而导致的一些缓冲区溢出,例如memcpy()
.
我的建议?避免在 Mac OS X 上使用 valgrind,除非您是very熟悉该工具。在 Linux 系统上编译并测试您的应用程序以获得最佳结果。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)