c – fprintf内存泄漏
我正在使用XCode 4.2.1中的仪器来查找一些内存泄漏.
我发现一个非常奇怪的(至少对我来说)内存泄漏: (函数values_table_get_value返回double,output = stdout) 这两个问题是: 为了显示泄漏是在fprintf内部,我将函数的返回值更改为5.0: 并将返回移动到一个临时变量: 更准确地说,这里是一个asm代码的图片,显示泄漏是: 我做了一个非常简单的测试:使用sprintf打印fprintf,但是我在sprintf中得到泄漏: 我也试图直接使用printf,我得到它的泄漏. 我真的认为问题是格式. 最后的尝试,显示没有任何与我的功能有关: 只是为了检查,我用valgrind执行:(values_table_print是函数名) 我的软件版本: 解决方法
不要浪费时间调试
您的设置可能有一个坏的gcc或valgrind构建或根本不是最新的. 我刚刚试过: gcc -o junk /tmp/junk.cpp && ~/src/valgrind/coregrind/valgrind --leak-check=full --show-reachable=yes /tmp/junk 在以下代码段中 #include <stdio.h> int main() { printf( "%.3f",3.0 ); } 组态 > OSX 10.7.2 使用内置的规格 Valgrind输出 ==58980== Memcheck,a memory error detector ==58980== Copyright (C) 2002-2010,and GNU GPL'd,by Julian Seward et al. ==58980== Using Valgrind-3.7.0.SVN and LibVEX; rerun with -h for copyright info ==58980== Command: /tmp/junk ==58980== --58980-- /tmp/junk: --58980-- dSYM directory is missing; consider using --dsymutil=yes UNKNOWN task message [id 3229,to mach_task_self(),reply 0x2503] UNKNOWN task message [id 3229,reply 0x2503] UNKNOWN task message [id 3414,reply 0x2503] --58980-- WARNING: unhandled syscall: unix:357 --58980-- You may be able to write your own handler. --58980-- Read the file README_MISSING_SYSCALL_OR_IOCTL. --58980-- Nevertheless we consider this a bug. Please report --58980-- it at http://valgrind.org/support/bug_reports.html. 3.000==58980== ==58980== HEAP SUMMARY: ==58980== in use at exit: 0 bytes in 0 blocks ==58980== total heap usage: 0 allocs,0 frees,0 bytes allocated ==58980== ==58980== All heap blocks were freed -- no leaks are possible ==58980== ==58980== For counts of detected and suppressed errors,rerun with: -v ==58980== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |