尝试释放指针时出现段错误

Segfaults when trying to free pointer

我有这样的代码

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);

}

第 "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.

我可以保证 "execution_time" 不会越界 find_execution_time() 我相信我释放了我在代码中所做的每一个 malloc

还发现 execution_time 的指针值在它使用 gdb

在 free() 崩溃之前是相同的

尝试了 valgrind,但它没有帮助,因为程序段错误

这可能是什么问题?

整个问题是,在 malloc 中我使用了错误的类型

对于缓冲区,我将其分配为

buffers  = (int *)malloc(sizeof(int)*node_count);

应该是

buffers  = (buffer *)malloc(sizeof(buffer)*node_count);

缓冲区是我代码中的结构类型。

太奇怪了,以一种根据错误消息无法找出的方式崩溃。

谢谢杰里米!和 pm100