about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-01-14 15:29:43 +0000
committerbors <bors@rust-lang.org>2020-01-14 15:29:43 +0000
commit8a87b945b27b5670ac5ed665bbb0fccc1b88a0a0 (patch)
tree54b1965761803218ab8de9e66368698ec4a1b49d /src/libstd
parentcb6122db3fa22031c48ca6b332fc856b8d098027 (diff)
parent25519e5290b4e04ab7a6cb07bcda01a542a0b1f3 (diff)
downloadrust-8a87b945b27b5670ac5ed665bbb0fccc1b88a0a0.tar.gz
rust-8a87b945b27b5670ac5ed665bbb0fccc1b88a0a0.zip
Auto merge of #67711 - Amanieu:fix_unwind_leak, r=alexcrichton
Fix memory leak if C++ catches a Rust panic and discards it

If C++ catches a Rust panic using `catch (...)` and then chooses not to rethrow it, the `Box<dyn Any>` in the exception may be leaked. This PR fixes this by adding the necessary destructors to the exception object.

r? @Mark-Simulacrum
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/panicking.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs
index 599ccc809be..bfadeafb7c7 100644
--- a/src/libstd/panicking.rs
+++ b/src/libstd/panicking.rs
@@ -55,6 +55,15 @@ extern "C" {
     fn __rust_start_panic(payload: usize) -> u32;
 }
 
+/// This function is called by the panic runtime if FFI code catches a Rust
+/// panic but doesn't rethrow it. We don't support this case since it messes
+/// with our panic count.
+#[cfg(not(test))]
+#[rustc_std_internal_symbol]
+extern "C" fn __rust_drop_panic() -> ! {
+    rtabort!("Rust panics must be rethrown");
+}
+
 #[derive(Copy, Clone)]
 enum Hook {
     Default,