[compiler-rt] [sanitizer_common][lsan] Keep the original allocation alive when realloc fails (PR #222849)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 10 23:08:37 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp,c -- compiler-rt/test/lsan/TestCases/Linux/realloc_failure_keeps_original.cpp compiler-rt/lib/lsan/lsan_allocator.cpp compiler-rt/lib/sanitizer_common/sanitizer_allocator_combined.h compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp compiler-rt/test/lsan/TestCases/realloc_zero.c --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/compiler-rt/lib/lsan/lsan_allocator.cpp b/compiler-rt/lib/lsan/lsan_allocator.cpp
index 8433626f6..16a27658a 100644
--- a/compiler-rt/lib/lsan/lsan_allocator.cpp
+++ b/compiler-rt/lib/lsan/lsan_allocator.cpp
@@ -140,11 +140,11 @@ void *Reallocate(const StackTrace &stack, void *p, uptr new_size,
return nullptr;
}
CHECK(allocator.PointerIsMine(p));
- ChunkMetadata *m = Metadata(p);
+ ChunkMetadata* m = Metadata(p);
CHECK(m);
const uptr old_size = m->requested_size;
// Allocate first: on failure p must be left untouched.
- void *new_p = Allocate(stack, new_size, alignment, false);
+ void* new_p = Allocate(stack, new_size, alignment, false);
if (!new_p)
return nullptr;
internal_memcpy(new_p, p, Min(new_size, old_size));
diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp
index 21d9e4180..77753b75f 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp
@@ -755,20 +755,20 @@ void TestCombinedAllocator(uptr premapped_heap = 0) {
// size-plus-alignment check inside Allocate(), which logs a warning.
{
const uptr kSize = 128;
- char *p = reinterpret_cast<char *>(a->Allocate(&cache, kSize, 1));
+ char* p = reinterpret_cast<char*>(a->Allocate(&cache, kSize, 1));
ASSERT_NE(p, nullptr);
- uptr *meta = reinterpret_cast<uptr *>(a->GetMetaData(p));
+ uptr* meta = reinterpret_cast<uptr*>(a->GetMetaData(p));
*meta = kSize;
internal_memset(p, 'x', kSize);
EXPECT_EQ(a->Reallocate(&cache, p, (uptr)-1, 1), nullptr);
// These hold even for a released chunk; the loop below is what detects it.
- EXPECT_EQ(*reinterpret_cast<uptr *>(a->GetMetaData(p)), kSize);
+ EXPECT_EQ(*reinterpret_cast<uptr*>(a->GetMetaData(p)), kSize);
EXPECT_EQ(p[0], 'x');
EXPECT_EQ(p[kSize - 1], 'x');
- void *others[8];
+ void* others[8];
for (uptr i = 0; i < ARRAY_SIZE(others); i++) {
others[i] = a->Allocate(&cache, kSize, 1);
EXPECT_NE(others[i], p);
@@ -785,17 +785,17 @@ void TestCombinedAllocator(uptr premapped_heap = 0) {
// leaves p unmapped, so assert ownership before reading through it.
{
const uptr kLarge = 1 << 20;
- void *p = a->Allocate(&cache, kLarge, 1);
+ void* p = a->Allocate(&cache, kLarge, 1);
ASSERT_NE(p, nullptr);
if (!a->FromPrimary(p)) {
- uptr *meta = reinterpret_cast<uptr *>(a->GetMetaData(p));
+ uptr* meta = reinterpret_cast<uptr*>(a->GetMetaData(p));
*meta = kLarge;
EXPECT_EQ(a->Reallocate(&cache, p, (uptr)-1, 1), nullptr);
ASSERT_TRUE(a->PointerIsMine(p));
EXPECT_EQ(a->GetBlockBegin(p), p);
- EXPECT_EQ(*reinterpret_cast<uptr *>(a->GetMetaData(p)), kLarge);
+ EXPECT_EQ(*reinterpret_cast<uptr*>(a->GetMetaData(p)), kLarge);
*meta = 0;
}
a->Deallocate(&cache, p);
``````````
</details>
https://github.com/llvm/llvm-project/pull/222849
More information about the llvm-commits
mailing list