Skip to content

Commit

Permalink
[scudo] Fix data leak in wrappers_c_test.cpp
Browse files Browse the repository at this point in the history
In SmallAlign implemented deallocation for the pointers

Reviewed By: cferris, Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D153480
  • Loading branch information
Riley authored and ChiaHungDuan committed Jun 26, 2023
1 parent b3e4283 commit 01c02ab
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "common.h"
#include "memtag.h"
#include "scudo/interface.h"
#include "tests/scudo_unit_test.h"
Expand All @@ -15,6 +16,7 @@
#include <malloc.h>
#include <stdlib.h>
#include <unistd.h>
#include <vector>

#ifndef __GLIBC_PREREQ
#define __GLIBC_PREREQ(x, y) 0
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 01c02ab

Please sign in to comment.