diff --git a/src/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp b/src/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp index ca40d04e36..2a0369206b 100644 --- a/src/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp +++ b/src/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp @@ -75,6 +75,8 @@ BOOL APIENTRY DllMain(HMODULE hModule, break; case DLL_PROCESS_DETACH: g_fProcessDetach = TRUE; + IN_PROCESS_HANDLER::StaticTerminate(); + ALLOC_CACHE_HANDLER::StaticTerminate(); DebugStop(); default: break; diff --git a/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.cpp b/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.cpp index 90b3bd9d53..0b7357f5d2 100644 --- a/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.cpp +++ b/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.cpp @@ -180,11 +180,18 @@ HRESULT Finished: if (FAILED(hr)) { - if (sm_pAlloc != NULL) - { - delete sm_pAlloc; - sm_pAlloc = NULL; - } + StaticTerminate(); } return hr; } + +// static +void +IN_PROCESS_HANDLER::StaticTerminate(VOID) +{ + if (sm_pAlloc != NULL) + { + delete sm_pAlloc; + sm_pAlloc = NULL; + } +} diff --git a/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.h b/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.h index fe0331da9b..ac6aa24789 100644 --- a/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.h +++ b/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.h @@ -70,6 +70,10 @@ public: HRESULT StaticInitialize(VOID); + static + void + StaticTerminate(VOID); + private: REQUEST_NOTIFICATION_STATUS ServerShutdownMessage() const; diff --git a/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cpp b/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cpp index d74571e953..d77c5c47d8 100644 --- a/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cpp +++ b/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cpp @@ -260,6 +260,8 @@ BOOL APIENTRY DllMain(HMODULE hModule, break; case DLL_PROCESS_DETACH: g_fProcessDetach = TRUE; + FORWARDING_HANDLER::StaticTerminate(); + ALLOC_CACHE_HANDLER::StaticTerminate(); DebugStop(); default: break;