bug fix: freeing buffer twice on sync()