Store return for realloc in a separate variable to check for NULL (failure), then on success assign it back to basenam