Fix a possible concurrent access violation