Fix bug caused buf to be shared across threads