Index: util/misc/initialization_state.h |
diff --git a/util/misc/initialization_state.h b/util/misc/initialization_state.h |
index b5a72031698e2b82048e300899877cfbc44b817c..b0496e5c131909733aa26ba9843d3a0feed5149c 100644 |
--- a/util/misc/initialization_state.h |
+++ b/util/misc/initialization_state.h |
@@ -86,7 +86,11 @@ class InitializationState { |
void set_state(State state) { state_ = state; } |
private: |
- State state_; |
+ // state_ is volatile to ensure that it’ll be set by the destructor when it |
+ // runs. Otherwise, optimizations might prevent it from ever being set to |
+ // kStateDestroyed, limiting this class’ ability to catch use-after-free |
+ // errors. |
+ volatile State state_; |
DISALLOW_COPY_AND_ASSIGN(InitializationState); |
}; |