call cleanup-function in thread_local_ptr

(cherry picked from commit fca6e0301a232993bf018c52285174a9098fbebe)