Prevent out of memory when using realloc.