[compiler-rt] 15664fe - [scudo][standalone] Fix for releaseToOS prior to init
Kostya Kortchinsky via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 25 08:39:01 PST 2019
Author: Kostya Kortchinsky
Date: 2019-11-25T08:38:45-08:00
New Revision: 15664fe2c48be242b4b38422466246e9592b6670
URL: https://github.com/llvm/llvm-project/commit/15664fe2c48be242b4b38422466246e9592b6670
DIFF: https://github.com/llvm/llvm-project/commit/15664fe2c48be242b4b38422466246e9592b6670.diff
LOG: [scudo][standalone] Fix for releaseToOS prior to init
Summary:
cferris@ found an issue where calling `releaseToOS` prior to any other
heap operation would lead to a crash, due to the allocator not being
properly initialized (it was discovered via `mallopt`).
The fix is to call `initThreadMaybe` prior to calling `releaseToOS` for
the Primary.
Add a test that crashes prior to fix.
Reviewers: hctim, cferris, pcc, eugenis
Subscribers: #sanitizers, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D70552
Added:
Modified:
compiler-rt/lib/scudo/standalone/combined.h
compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h
index 0a05857a20d6..8560c2d3599f 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -402,7 +402,10 @@ template <class Params> class Allocator {
Str.output();
}
- void releaseToOS() { Primary.releaseToOS(); }
+ void releaseToOS() {
+ initThreadMaybe();
+ Primary.releaseToOS();
+ }
// Iterate over all chunks and call a callback for all busy chunks located
// within the provided memory range. Said callback must not use this allocator
diff --git a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
index d32ea89e0ea3..9205467998ed 100644
--- a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
@@ -279,3 +279,18 @@ TEST(ScudoCombinedTest, DeathCombined) {
EXPECT_DEATH(Allocator->reallocate(P, Size * 2U), "");
EXPECT_DEATH(Allocator->getUsableSize(P), "");
}
+
+// Ensure that releaseToOS can be called prior to any other allocator
+// operation without issue.
+TEST(ScudoCombinedTest, ReleaseToOS) {
+ using AllocatorT = scudo::Allocator<DeathConfig>;
+ auto Deleter = [](AllocatorT *A) {
+ A->unmapTestOnly();
+ delete A;
+ };
+ std::unique_ptr<AllocatorT, decltype(Deleter)> Allocator(new AllocatorT,
+ Deleter);
+ Allocator->reset();
+
+ Allocator->releaseToOS();
+}
More information about the llvm-commits
mailing list