Fix issue: possible memory leak due to uncleaned threadlocoal