bug fix: freeing buffer twice