Fix a TOCTOU issue by locking before stat