Memory leak. First realloc, then check, then assign.