当我尝试释放我的循环缓冲区时,我收到一个断言错误(表达式:crtisvalidheapppointer)。为什么会这样?
相关结构:
typedef struct quote {
unsigned int seconds;
double rate;
} quote;
typedef struct cbuf {
unsigned int max;
unsigned int start;
unsigned int end;
unsigned int size;
quote *quotes;
} cbuf;
malloc 和释放的代码块:
#define INITIAL_SIZE 10
static cbuf cb1 = {INITIAL_SIZE, 0, 0, 0, NULL};
cb1.quotes = (quote*)malloc(INITIAL_SIZE * sizeof(quote));
if(cb1.quotes == NULL)
{
printf("Error - memory allocation failed.");
exit(1);
}
free(&cb1);