2
下面的代碼在fclose()
呼叫中斷。free():fclose上的下一個尺寸(正常)無效。但Valgrind運行時不能運行
void output_gauss_transform(char* filename, char* mode, double** T,
double shift, int len)
{
FILE* fp;
printf("Outputting gauss transform to %s.\n", filename);
if ((fp = fopen(filename, mode)) == NULL){
perror("Could not open file");
return;
}
int i;
for (i = 0; i < len; ++i) {
fprintf(fp, "%lf %lf\n", T[0][i], T[1][i] + shift);
}
if (fclose(fp)){
printf("error closing\n");
}
}
glibc
給我這個錯誤,以及內存映射。
*** glibc detected *** [sourcedir]/.libs/lt-launcher: free(): invalid next size (normal): 0x0821da38 ***
======= Backtrace: =========
/lib/i386-linux-gnu/libc.so.6(+0x75ee2)[0xb739dee2]
/lib/i386-linux-gnu/libc.so.6(fclose+0x154)[0xb738d424]
/src/.libs/libfile_util.so.0(output_gauss_transform+0xa9)[0xb77b5859]
/src/.libs/lt-launcher[0x804a0f9]
/src/.libs/lt-launcher[0x804a2a5]
/src/.libs/lt-launcher[0x804983b]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0xb73414d3]
/src/.libs/lt-launcher[0x8049915]
當試圖與valgrind
調試這個,我沒有得到任何錯誤,標明它輸出以下。到底是怎麼回事?
==30396== HEAP SUMMARY:
==30396== in use at exit: 0 bytes in 0 blocks
==30396== total heap usage: 1,059 allocs, 1,059 frees, 78,149 bytes allocated
==30396==
==30396== All heap blocks were freed -- no leaks are possible
==30396==
==30396== For counts of detected and suppressed errors, rerun with: -v
==30396== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
編輯:用-v
運行valgrind
,我在最後得到這個東西。也許這跟正在發生的事情有關係?
--31325-- REDIR: 0x454cac0 (operator delete(void*)) redirected to 0x402bb98 (operator delete(void*))
是否有任何開關可用於使Valgrind的檢查更嚴格? – heuristicus
看看'--redzone-size'和'--freelist-vol'。你的程序是否用內存分配來做任何奇怪的事情? (例如,從庫中獲得一個對象,然後釋放它,實現自己的「重新使用最近釋放的對象」行爲,或類似的東西?) –