summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2023-01-13 06:30:08 +0000
committerChristopher Ferris <cferris@google.com>2023-01-19 00:39:03 +0000
commit4eba55790224dd43e88d6a4bbf4fea826a59498f (patch)
tree0f48feccac97d8f993299973e7a8b33aa7b817d8
parentcf5522daa58261e7f7edd04a3e474b94dd327435 (diff)
downloadrustc-demangle-capi-4eba55790224dd43e88d6a4bbf4fea826a59498f.tar.gz
Fix memory leak.
The buffer to hold the demangled name is allocated before the name is demangled. If the parse fails, this buffer is not deallocated, leaking it. Only create the buffer when the parse passes. Test: Ran address sanitizer on host and verified this leaks without Test: the fix and does not with the fix. Change-Id: I3ee20727972fc511f63aae2b50f5a34f0c792a5f
-rw-r--r--src/lib.rs3
1 files changed, 1 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 7610145..d220ec1 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -163,10 +163,9 @@ unsafe fn rustc_demangle_native(
}
}
- let mut out_buf = SystemBuffer::from_raw(out, out_size)?;
-
match rustc_demangle::try_demangle(mangled_str) {
Ok(demangle) => {
+ let mut out_buf = SystemBuffer::from_raw(out, out_size)?;
while write!(out_buf.as_mut_slice(), "{:#}\0", demangle).is_err() {
out_buf.resize()?;
}