Reset released string parameter correctly
Do not cast return value of malloc/realloc
Free allocation upon realloc failure