Realloc fail on union

Did you read the docs on realloc, in particular

Reallocates the given area of memory. It must be previously allocated by malloc(), calloc() or realloc() and not yet freed with a call to free or realloc . Otherwise, the results are undefined.

https://en.cppreference.com/w/c/memory/realloc

I can’t seem to find where you explicitly allocate memory in your code