0

循環バッファーを解放しようとすると、アサーション エラー (式: crtisvalidheappointer) が発生します。なぜこうなった?

関連する構造体:

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 と free を行うコードのブロック:

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

3 に答える 3