小编use*_*921的帖子

c程序中的双重免费或损坏(!prev)错误

运行ac程序时出现以下错误:

*** glibc detected *** ./a.out: double free or corruption (!prev): 0x080b8008 ***
Run Code Online (Sandbox Code Playgroud)

我相信这是因为在程序结束时调用了free(),但我无法弄清楚malloc内存在此之前被释放的位置.这是代码:

#include <stdio.h>
#include <stdlib.h> //malloc
#include <math.h>  //sine

#define TIME 255
#define HARM 32

int main (void) {
    double sineRads;
    double sine;
    int tcount = 0;
    int hcount = 0;
    /* allocate some heap memory for the large array of waveform data */
    double *ptr = malloc(sizeof(double *) * TIME);
    if (NULL == ptr) {
        printf("ERROR: couldn't allocate waveform memory!\n");
    } else {
        /*evaluate and add …
Run Code Online (Sandbox Code Playgroud)

c free

24
推荐指数
2
解决办法
9万
查看次数

标签 统计

c ×1

free ×1