I'm not that new to coding but I faced a problem I couldn't explain to myself.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *test;
test = (char *)calloc(15, sizeof(char));
// test = "Wurstbrot";
free(test);
}
If I compile this, test gets malloced and directly freed (what I expected).
But if I uncomment the comment, I get this error while compiling:
a.out(28953,0x104403dc0) malloc: *** error for object 0x10365cfae: pointer being freed was not allocated
a.out(28953,0x104403dc0) malloc: *** set a breakpoint in malloc_error_break to debug
zsh: abort ./a.out
When I remove the free function, it will work again.
My question now: why is it a problem here to free an initialized pointer?