Fixed a resource leak in ThreadLocal.

Review: https://reviews.apache.org/r/24669