Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(882)

Side by Side Diff: Source/wtf/PartitionAllocTest.cpp

Issue 645223007: PartitionAlloc: Leave bucket in valid state when allocation fails (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add fix Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/wtf/PartitionAlloc.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 ptr = partitionAllocGeneric(genericAllocator.root(), size); 1090 ptr = partitionAllocGeneric(genericAllocator.root(), size);
1091 EXPECT_TRUE(ptr); 1091 EXPECT_TRUE(ptr);
1092 partitionFreeGeneric(genericAllocator.root(), ptr); 1092 partitionFreeGeneric(genericAllocator.root(), ptr);
1093 1093
1094 EXPECT_TRUE(bucket->activePagesHead); 1094 EXPECT_TRUE(bucket->activePagesHead);
1095 EXPECT_TRUE(bucket->freePagesHead); 1095 EXPECT_TRUE(bucket->freePagesHead);
1096 1096
1097 TestShutdown(); 1097 TestShutdown();
1098 } 1098 }
1099 1099
1100 // Tests that if an allocation fails in "return null" mode, repeating it doesn't
1101 // crash, and still returns null. The test allocates 6 GB of memory in 512 kB
1102 // blocks. This may never fail on 64-bit systems, in which case this test fails
Jens Widell 2014/10/22 19:40:12 To make these allocations fail on 64-bit, I've bee
1103 // to test what it sets out to test.
1104 TEST(PartitionAllocTest, RepeatedReturnNull)
1105 {
1106 TestSetup();
1107
1108 void* ptrs[8192];
1109 int i;
1110
1111 for (i = 0; i < 6144; ++i) {
1112 ptrs[i] = partitionAllocGenericFlags(genericAllocator.root(), WTF::Parti tionAllocReturnNull, 512*1024);
1113 if (!ptrs[i]) {
1114 ptrs[i] = partitionAllocGenericFlags(genericAllocator.root(), WTF::P artitionAllocReturnNull, 512*1024);
1115 EXPECT_FALSE(ptrs[i]);
1116 break;
1117 }
1118 }
1119
1120 for (--i; i >= 0; --i) {
1121 partitionFreeGeneric(genericAllocator.root(), ptrs[i]);
1122 ptrs[i] = partitionAllocGenericFlags(genericAllocator.root(), WTF::Parti tionAllocReturnNull, 512*1024);
1123 partitionFreeGeneric(genericAllocator.root(), ptrs[i]);
1124 }
1125
1126 TestShutdown();
1127 }
1128
1100 #if !OS(ANDROID) 1129 #if !OS(ANDROID)
1101 1130
1102 // Make sure that malloc(-1) dies. 1131 // Make sure that malloc(-1) dies.
1103 // In the past, we had an integer overflow that would alias malloc(-1) to 1132 // In the past, we had an integer overflow that would alias malloc(-1) to
1104 // malloc(0), which is not good. 1133 // malloc(0), which is not good.
1105 TEST(PartitionAllocDeathTest, LargeAllocs) 1134 TEST(PartitionAllocDeathTest, LargeAllocs)
1106 { 1135 {
1107 TestSetup(); 1136 TestSetup();
1108 // Largest alloc. 1137 // Largest alloc.
1109 EXPECT_DEATH(partitionAllocGeneric(genericAllocator.root(), static_cast<size _t>(-1)), ""); 1138 EXPECT_DEATH(partitionAllocGeneric(genericAllocator.root(), static_cast<size _t>(-1)), "");
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 EXPECT_EQ(32u, WTF::countLeadingZerosSizet(0u)); 1218 EXPECT_EQ(32u, WTF::countLeadingZerosSizet(0u));
1190 EXPECT_EQ(31u, WTF::countLeadingZerosSizet(1u)); 1219 EXPECT_EQ(31u, WTF::countLeadingZerosSizet(1u));
1191 EXPECT_EQ(1u, WTF::countLeadingZerosSizet(1u << 30)); 1220 EXPECT_EQ(1u, WTF::countLeadingZerosSizet(1u << 30));
1192 EXPECT_EQ(0u, WTF::countLeadingZerosSizet(1u << 31)); 1221 EXPECT_EQ(0u, WTF::countLeadingZerosSizet(1u << 31));
1193 #endif 1222 #endif
1194 } 1223 }
1195 1224
1196 } // namespace 1225 } // namespace
1197 1226
1198 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 1227 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
OLDNEW
« no previous file with comments | « Source/wtf/PartitionAlloc.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698