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

Unified Diff: base/allocator/tcmalloc_free_check_test.cc

Issue 10391178: 1. Enable large object pointer offset check in release build. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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: base/allocator/tcmalloc_free_check_test.cc
===================================================================
--- base/allocator/tcmalloc_free_check_test.cc (revision 0)
+++ base/allocator/tcmalloc_free_check_test.cc (working copy)
@@ -0,0 +1,49 @@
+// Copyright 2012 Google Inc. All Rights Reserved.
+// Author: kaiwang@google.com (Kai Wang)
+
+#include <stdio.h>
+#include "base/allocator/allocator_shim.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+// TCMalloc header files
+#include "common.h" // For TCMalloc constants like page size, etc.
+
+using base::allocator::TCMallocDoMallocForTest;
+using base::allocator::TCMallocDoFreeForTest;
+
+TEST(TCMallocFreeCheck, BadPointerInFirstPageOfTheLargeObject) {
+ volatile int* p =
+ reinterpret_cast<volatile int*>(TCMallocDoMallocForTest(kMaxSize + 1));
jar (doing other things) 2012/05/17 01:36:41 nit: No need for volatile here.
kaiwang 2012/05/19 00:12:27 Done.
+ ASSERT_DEATH(TCMallocDoFreeForTest(const_cast<int*>(p + kAlignment)),
jar (doing other things) 2012/05/17 01:36:41 Perhaps try adding small powers of two: 1, 2, 4, 8
kaiwang 2012/05/19 00:12:27 Done.
+ "Pointer not pointed to the start of a span");
+}
+
+TEST(TCMallocFreeCheck, BadPointerInSubsequentPagesOfTheLargeObject) {
jar (doing other things) 2012/05/17 01:36:41 nit: suggest better name: BadPageAlignedPointerIns
kaiwang 2012/05/19 00:12:27 Done.
+ volatile int* p =
+ reinterpret_cast<volatile int*>(TCMallocDoMallocForTest(kMaxSize + 1));
+ ASSERT_DEATH(TCMallocDoFreeForTest(const_cast<int*>(p + kPageSize)),
jar (doing other things) 2012/05/17 01:36:41 perhaps iterate at page boundaries (but stay insid
+ "Attempt to free invalid pointer");
+}
+/*
+#ifndef NDEBUG
+TEST(TCMallocFreeCheck, DoubleFreeLargeObject) {
+ volatile int* p =
+ reinterpret_cast<volatile int*>(TCMallocDoMallocForTest(kMaxSize + 1));
+ TCMallocDoFreeForTest(const_cast<int*>(p));
+ ASSERT_DEATH(TCMallocDoFreeForTest(const_cast<int*>(p)),
+ "Attempt to double free");
+}
+
+TEST(TCMallocFreeCheck, DoubleFreeSmallObject) {
+ volatile int* p =
+ reinterpret_cast<volatile int*>(TCMallocDoMallocForTest(kMaxSize));
+ TCMallocDoFreeForTest(const_cast<int*>(p));
+ ASSERT_DEATH(TCMallocDoFreeForTest(const_cast<int*>(p)),
+ "Attempt to double free");
+}
+#endif
+*/
+int main(int argc, char **argv) {
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}

Powered by Google App Engine
This is Rietveld 408576698