fixed segfault when realloc-ing results buffer