Fix a read after free
This fixes a read after the memory has been freed (realloc'ed). There is also a trivial fix to the indentation.
Just let me know if you would like me to do the change in a different way. E.g. do a malloc+free instead of realloc.