Use localtime_r instead of localtime

localtime is not reentrant.