运行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)