[compiler-rt] 01c02ab - [scudo] Fix data leak in wrappers_c_test.cpp
Chia-hung Duan via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 26 15:44:10 PDT 2023
Author: Riley
Date: 2023-06-26T22:37:58Z
New Revision: 01c02abc540d34b3627c19d7fc5405e35821a0df
URL: https://github.com/llvm/llvm-project/commit/01c02abc540d34b3627c19d7fc5405e35821a0df
DIFF: https://github.com/llvm/llvm-project/commit/01c02abc540d34b3627c19d7fc5405e35821a0df.diff
LOG: [scudo] Fix data leak in wrappers_c_test.cpp
In SmallAlign implemented deallocation for the pointers
Reviewed By: cferris, Chia-hungDuan
Differential Revision: https://reviews.llvm.org/D153480
Added:
Modified:
compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
index ebf66e1c92e7c..7074cdcee151a 100644
--- a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "common.h"
#include "memtag.h"
#include "scudo/interface.h"
#include "tests/scudo_unit_test.h"
@@ -15,6 +16,7 @@
#include <malloc.h>
#include <stdlib.h>
#include <unistd.h>
+#include <vector>
#ifndef __GLIBC_PREREQ
#define __GLIBC_PREREQ(x, y) 0
@@ -115,15 +117,24 @@ TEST(ScudoWrappersCTest, Calloc) {
}
TEST(ScudoWrappersCTest, SmallAlign) {
- void *P;
- for (size_t Size = 1; Size <= 0x10000; Size <<= 1) {
- for (size_t Align = 1; Align <= 0x10000; Align <<= 1) {
+ // Allocating pointers by the powers of 2 from 1 to 0x10000
+ // Using powers of 2 due to memalign using powers of 2 and test more sizes
+ constexpr size_t MaxSize = 0x10000;
+ std::vector<void *> ptrs;
+ // Reserving space to prevent further allocation during the test
+ ptrs.reserve((scudo::getLeastSignificantSetBitIndex(MaxSize) + 1) *
+ (scudo::getLeastSignificantSetBitIndex(MaxSize) + 1) * 3);
+ for (size_t Size = 1; Size <= MaxSize; Size <<= 1) {
+ for (size_t Align = 1; Align <= MaxSize; Align <<= 1) {
for (size_t Count = 0; Count < 3; ++Count) {
- P = memalign(Align, Size);
+ void *P = memalign(Align, Size);
EXPECT_TRUE(reinterpret_cast<uintptr_t>(P) % Align == 0);
+ ptrs.push_back(P);
}
}
}
+ for (void *ptr : ptrs)
+ free(ptr);
}
TEST(ScudoWrappersCTest, Memalign) {
More information about the llvm-commits
mailing list