realloc bugfix from upstream