Fix a possible stat-open race condition