diff options
author | Jan Vorlicek <janvorli@microsoft.com> | 2015-09-04 15:19:46 +0200 |
---|---|---|
committer | Jan Vorlicek <janvorli@microsoft.com> | 2015-09-04 22:22:27 +0200 |
commit | 88cf961965911b21f26699ac35ad5223e6f4496a (patch) | |
tree | f85fed3705ba7a1b479dfe169fb6553b528b7bae /src/vm/amd64/unixasmhelpers.S | |
parent | 1165038551b7ca20f230d867dc5fd2357ede14fe (diff) | |
download | coreclr-88cf961965911b21f26699ac35ad5223e6f4496a.tar.gz coreclr-88cf961965911b21f26699ac35ad5223e6f4496a.tar.bz2 coreclr-88cf961965911b21f26699ac35ad5223e6f4496a.zip |
Fix memory leak from managed exceptions
Handling thrown PAL_SEHException was causing leaks for all exceptions thrown due to
two aspects:
1) PAL_GetStackBase() and PAL_GetStackLimit() were missing calls to pthread_attr_destroy()
2) We were calling the DispatchManagedException from C++ catch handlers and this function
never returns. So the C++ exception handling never called __cxa_end_catch that is
responsible for freeing the exception storage allocated by the C++ runtime.
The fix to the 2nd aspect was to store a copy of the exception in the catch handler, let it
complete and then call the DispatchManagedException with the copy. It was also necessary to
slightly modify the unwinding of sequences of native frames since there is now no rethrowable
exception and the StartUnwindingManagedFrames has to throw a new one.
This change has a secondary benefit - the StartUnwindingManagedFrames no longer calls
__cxa_rethrow, but rather a helper C++ function that uses regular "throw" keyword.
That makes the code more portable.
Diffstat (limited to 'src/vm/amd64/unixasmhelpers.S')
-rw-r--r-- | src/vm/amd64/unixasmhelpers.S | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/vm/amd64/unixasmhelpers.S b/src/vm/amd64/unixasmhelpers.S index e3f4adc259..ccf552367c 100644 --- a/src/vm/amd64/unixasmhelpers.S +++ b/src/vm/amd64/unixasmhelpers.S @@ -291,7 +291,7 @@ LEAF_END SinglecastDelegateInvokeStub, _TEXT // from the passed in context and finally sets the RSP to that frame and sets the return // address to the target frame's RIP. // -// EXTERN_C void StartUnwindingNativeFrames(CONTEXT* context); +// EXTERN_C void StartUnwindingNativeFrames(CONTEXT* context, PAL_SEHException* ex); LEAF_ENTRY StartUnwindingNativeFrames, _TEXT // Save the RBP to the stack so that the unwind can work at the instruction after // loading the RBP from the context, but before loading the RSP from the context. @@ -316,6 +316,8 @@ LEAF_ENTRY StartUnwindingNativeFrames, _TEXT // Store return address to the stack push_register rax push_nonvol_reg rbp - call EXTERNAL_C_FUNC(__cxa_rethrow) + // The PAL_SEHException pointer + mov rdi, rsi + call EXTERNAL_C_FUNC(ThrowExceptionHelper) LEAF_END StartUnwindingNativeFrames, _TEXT |