Fix don't leak memory when realloc fails