Commit c3fdf2de authored by Benoit Lize's avatar Benoit Lize Committed by Commit Bot

base/allocator: Use the proper Free() in PartitionAlloc tests.

PartitionFree() should not be called on data allocated with
PartitionRoot*Generic*Alloc(). This happens to work, but is incorrect.

This is part of a larger refactoring of PartitionAlloc (see linked bug).

Bug: 1061437, 787153
Change-Id: Iad10ca5c89ed466584c7576958dbf8e77a243b6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2144139Reviewed-by: default avatarChris Palmer <palmer@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Benoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758757}
parent 6c5bb2b2
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include <vector> #include <vector>
#include "base/allocator/partition_allocator/address_space_randomization.h" #include "base/allocator/partition_allocator/address_space_randomization.h"
#include "base/allocator/partition_allocator/partition_alloc.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/stl_util.h" #include "base/stl_util.h"
...@@ -110,9 +109,8 @@ void AllocateRandomly(base::PartitionRootGeneric* root, ...@@ -110,9 +109,8 @@ void AllocateRandomly(base::PartitionRootGeneric* root,
} }
for (size_t i = 0; i < count; ++i) { for (size_t i = 0; i < count; ++i) {
if (allocations[i]) { if (allocations[i])
base::PartitionFree(allocations[i]); root->Free(allocations[i]);
}
} }
} }
...@@ -2200,7 +2198,7 @@ TEST_F(PartitionAllocTest, ZeroFill) { ...@@ -2200,7 +2198,7 @@ TEST_F(PartitionAllocTest, ZeroFill) {
} }
EXPECT_EQ(kAllZerosSentinel, non_zero_position) EXPECT_EQ(kAllZerosSentinel, non_zero_position)
<< "test allocation size: " << size; << "test allocation size: " << size;
PartitionFree(p); generic_allocator.root()->Free(p);
} }
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
...@@ -2224,7 +2222,7 @@ TEST_F(PartitionAllocTest, Bug_897585) { ...@@ -2224,7 +2222,7 @@ TEST_F(PartitionAllocTest, Bug_897585) {
kDesiredSize, nullptr); kDesiredSize, nullptr);
ASSERT_NE(nullptr, ptr); ASSERT_NE(nullptr, ptr);
memset(ptr, 0xbd, kDesiredSize); memset(ptr, 0xbd, kDesiredSize);
PartitionFree(ptr); generic_allocator.root()->Free(ptr);
} }
TEST_F(PartitionAllocTest, OverrideHooks) { TEST_F(PartitionAllocTest, OverrideHooks) {
...@@ -2266,7 +2264,7 @@ TEST_F(PartitionAllocTest, OverrideHooks) { ...@@ -2266,7 +2264,7 @@ TEST_F(PartitionAllocTest, OverrideHooks) {
kOverriddenSize, kOverriddenType); kOverriddenSize, kOverriddenType);
ASSERT_EQ(ptr, overridden_allocation); ASSERT_EQ(ptr, overridden_allocation);
PartitionFree(ptr); generic_allocator.root()->Free(ptr);
EXPECT_TRUE(free_called); EXPECT_TRUE(free_called);
// overridden_allocation has not actually been freed so we can now immediately // overridden_allocation has not actually been freed so we can now immediately
...@@ -2278,7 +2276,7 @@ TEST_F(PartitionAllocTest, OverrideHooks) { ...@@ -2278,7 +2276,7 @@ TEST_F(PartitionAllocTest, OverrideHooks) {
EXPECT_NE(ptr, overridden_allocation); EXPECT_NE(ptr, overridden_allocation);
EXPECT_TRUE(free_called); EXPECT_TRUE(free_called);
EXPECT_EQ(*(char*)ptr, kOverriddenChar); EXPECT_EQ(*(char*)ptr, kOverriddenChar);
PartitionFree(ptr); generic_allocator.root()->Free(ptr);
PartitionAllocHooks::SetOverrideHooks(nullptr, nullptr, nullptr); PartitionAllocHooks::SetOverrideHooks(nullptr, nullptr, nullptr);
free(overridden_allocation); free(overridden_allocation);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment