error handling for realloc