summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-07 05:16:46 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-07 05:16:46 +0000
commitabafe38a58dba123fc3ab08314d6ebaa954bb883 (patch)
tree29d976dd5aad9367db95c6de5128417a87264327
parentbd00f28c25a9d17d8fffa4effd9fc803927b8918 (diff)
parent3a543e6f6c078bdff87fb6f4348a9791716ac05c (diff)
downloadrustc-demangle-capi-android14-mainline-uwb-release.tar.gz
Change-Id: I1cdd9ebcb8d73765d56ff74b272d7b164c7cc287
-rw-r--r--BUILD.bazel7
-rw-r--r--patches/0003-Fix-memory-leak.patch36
-rw-r--r--src/lib.rs3
3 files changed, 44 insertions, 2 deletions
diff --git a/BUILD.bazel b/BUILD.bazel
new file mode 100644
index 0000000..9675457
--- /dev/null
+++ b/BUILD.bazel
@@ -0,0 +1,7 @@
+# TODO(b/266459895): remove these after re-enabling libunwindstack
+
+load("//build/bazel/rules/cc:cc_library_static.bzl", "cc_library_static")
+
+cc_library_static(
+ name = "librustc_demangle_static",
+)
diff --git a/patches/0003-Fix-memory-leak.patch b/patches/0003-Fix-memory-leak.patch
new file mode 100644
index 0000000..42aae07
--- /dev/null
+++ b/patches/0003-Fix-memory-leak.patch
@@ -0,0 +1,36 @@
+From 4eba55790224dd43e88d6a4bbf4fea826a59498f Mon Sep 17 00:00:00 2001
+From: Christopher Ferris <cferris@google.com>
+Date: Fri, 13 Jan 2023 06:30:08 +0000
+Subject: [PATCH] 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
+---
+ src/lib.rs | 3 +--
+ 1 file changed, 1 insertion(+), 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()?;
+ }
+--
+2.39.0.246.g2a6d74b583-goog
+
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()?;
}