when I compile this piece of code, the pointer freed not allocated error pops up. Could someone please explain why that is? Thank you!
static int make_buffer(FILE *input, char *buffer[]){
*buffer = (char *)malloc(INIT_BUFFER_SIZE*sizeof(char));
int buffer_size = INIT_BUFFER_SIZE;
int txt_size = 0;
char cha;
while((cha = fgetc(input)) != EOF){
if (txt_size == buffer_size){
*buffer = (char *)realloc(buffer, buffer_size*2*sizeof(char));
buffer_size *= 2;
}
(*buffer)[txt_size] = cha;
txt_size ++;
}
free(*buffer);
return txt_size;
}