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

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

Issue 7050034: Merge google-perftools r109 (the current contents of third_party/tcmalloc/vendor) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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 87277)
+++ third_party/tcmalloc/chromium/src/tests/debugallocation_test.cc (working copy)
@@ -213,6 +213,17 @@
*x = old_x_value; // restore x so that the test can exit successfully.
}
+TEST(DebugAllocationTest, StackTraceWithDanglingWriteAtExitTest) {
+ int *x = new int;
+ delete x;
+ int old_x_value = *x;
+ *x = 1;
+ // verify that we also get a stack trace when we have a dangling write.
+ // The " @ " is part of the stack trace output.
+ IF_DEBUG_EXPECT_DEATH(exit(0), " @ .*main");
+ *x = old_x_value; // restore x so that the test can exit successfully.
+}
+
static size_t CurrentlyAllocatedBytes() {
size_t value;
CHECK(MallocExtension::instance()->GetNumericProperty(
@@ -259,27 +270,24 @@
}
TEST(DebugAllocationTest, HugeAlloc) {
- const size_t kTooBig = ~static_cast<size_t>(0);
+ // This must not be a const variable so it doesn't form an
+ // integral-constant-expression which can be *statically* rejected by the
+ // compiler as too large for the allocation.
+ 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;
+ // but will still fall through to tcmalloc's check. This must also be
+ // a non-const variable. See kTooBig for more details.
+ 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
}

Powered by Google App Engine
This is Rietveld 408576698