Saya punya kode seperti ini
void find_groupings ()
int *bandwidths;
int *execution_time;
bandwidths = (int *)malloc(sizeof(int)*node_count); // node_count is glbl
execution_time = (int *)malloc(sizeof(int)*node_count);
//other mallocs, other code etc
while (condition) {
// lot of code
find_bandwidths(bandwidths);
find_execution_time(execution_time);
//lot of code
}
free(bandwidths);
free(execution_time);
}
kode segfault pada baris "free(execution_time);"
Thread 1 "vx_tutorial_exe" received signal SIGSEGV, Segmentation fault.
0xf7dd0cd9 in _int_free (av=0xf7f15780 <main_arena>, p=<optimized out>, have_lock=0) at malloc.c:4005
4005 malloc.c: No such file or directory.
Saya dapat menjamin bahwa "execution_time" tidak keluar batas di dalam find_execution_time() Saya yakin saya membebaskan setiap malloc yang saya lakukan dalam kode
Ditemukan juga bahwa nilai penunjuk untuk waktu_eksekusi sama sebelum mogok di free() menggunakan gdb
mencoba valgrind tetapi, itu tidak membantu karena programnya segfault
Apa masalahnya di sini?
other code
bit. Atau mungkin mallocs Anda gagal. Setidaknya tes untuk nol - person pm100   schedule 20.09.2018