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

Unified Diff: third_party/tcmalloc/chromium/src/tests/debugallocation_test.cc

Issue 576001: Merged third_party/tcmalloc/vendor/src(google-perftools r87) into... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Removed the unnecessary printf and ASSERT(0) Created 10 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: third_party/tcmalloc/chromium/src/tests/debugallocation_test.cc
===================================================================
--- third_party/tcmalloc/chromium/src/tests/debugallocation_test.cc (revision 41942)
+++ third_party/tcmalloc/chromium/src/tests/debugallocation_test.cc (working copy)
@@ -102,6 +102,28 @@
}
}
+TEST(DebugAllocationTest, DoubleFree) {
+ int* pint = new int;
+ delete pint;
+ IF_DEBUG_EXPECT_DEATH(delete pint, "has been already deallocated");
+}
+
+TEST(DebugAllocationTest, StompBefore) {
+ int* pint = new int;
+#ifndef NDEBUG // don't stomp memory if we're not in a position to detect it
+ pint[-1] = 5;
+ IF_DEBUG_EXPECT_DEATH(delete pint, "a word before object");
+#endif
+}
+
+TEST(DebugAllocationTest, StompAfter) {
+ int* pint = new int;
+#ifndef NDEBUG // don't stomp memory if we're not in a position to detect it
+ pint[1] = 5;
+ IF_DEBUG_EXPECT_DEATH(delete pint, "a word after object");
+#endif
+}
+
TEST(DebugAllocationTest, FreeQueueTest) {
// Verify that the allocator doesn't return blocks that were recently freed.
int* x = new int;
@@ -205,6 +227,31 @@
free(a);
}
+TEST(DebugAllocationTest, HugeAlloc) {
+ const size_t kTooBig = ~static_cast<size_t>(0);
+ void* a = NULL;
+ char* b = NULL;
+
+#ifndef NDEBUG
+
+ a = malloc(kTooBig);
+ EXPECT_EQ(NULL, a);
+ b = NULL;
+ IF_DEBUG_EXPECT_DEATH(b = new char[kTooBig],
+ "Unable to allocate.*new\\[\\] failed\\.");
+ EXPECT_EQ(NULL, b);
+
+ // kAlsoTooBig is small enough not to get caught by debugallocation's check,
+ // but will still fall through to tcmalloc's check.
+ const size_t kAlsoTooBig = kTooBig - 1024;
+
+ a = malloc(kAlsoTooBig);
+ EXPECT_EQ(NULL, a);
+ IF_DEBUG_EXPECT_DEATH(b = new char[kAlsoTooBig], "Unable to allocate.*new failed");
+ EXPECT_EQ(NULL, b);
+#endif
+}
+
int main(int argc, char** argv) {
// If you run without args, we run the non-death parts of the test.
// Otherwise, argv[1] should be a number saying which death-test

Powered by Google App Engine
This is Rietveld 408576698