File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -103,7 +103,22 @@ namespace snmalloc
103
103
104
104
static void initialise_for_singleton (size_t *) noexcept
105
105
{
106
- AddVectoredExceptionHandler (1 , HandleReadonlyLazyCommit);
106
+ // Keep a handle for the exception handler, so we can remove it later
107
+ // when needed.
108
+ static PVOID g_Handler{};
109
+ // Destructor for removing exception handler.
110
+ static OnDestruct tidy ([]() {
111
+ if (g_Handler)
112
+ {
113
+ RemoveVectoredExceptionHandler (g_Handler);
114
+ g_Handler = NULL ; // Prevent dangling pointer
115
+ }
116
+ });
117
+ // Add exception handler for lazy commit.
118
+ if (!g_Handler)
119
+ {
120
+ g_Handler = AddVectoredExceptionHandler (1 , HandleReadonlyLazyCommit);
121
+ }
107
122
}
108
123
109
124
// Ensure the exception handler is registered.
You can’t perform that action at this time.
0 commit comments