summaryrefslogtreecommitdiffstats
path: root/vespamalloc
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@broadpark.no>2019-11-10 18:35:03 +0100
committerTor Egge <Tor.Egge@broadpark.no>2019-11-10 18:35:03 +0100
commit2a5bb946e10778421d167d71a52128471a221051 (patch)
treee54f9874898fead596ecfdefb5ac930f537dbefb /vespamalloc
parent2269896f0e1cff129fc5ebc5a29e0c6400c2f519 (diff)
Don't optimize away new/delete pairs.
Diffstat (limited to 'vespamalloc')
-rw-r--r--vespamalloc/src/tests/overwrite/overwrite.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/vespamalloc/src/tests/overwrite/overwrite.cpp b/vespamalloc/src/tests/overwrite/overwrite.cpp
index fb167c0e4d2..b016c13ab61 100644
--- a/vespamalloc/src/tests/overwrite/overwrite.cpp
+++ b/vespamalloc/src/tests/overwrite/overwrite.cpp
@@ -3,6 +3,13 @@
using namespace vespalib;
+void check_ptr_real(void *ptr)
+{
+ (void) ptr;
+}
+
+void (*check_ptr)(void *ptr) = check_ptr_real;
+
class Test : public TestApp
{
public:
@@ -30,6 +37,7 @@ void Test::testFillValue(char *a)
for (size_t i(0); i < 100; i++) {
char *d = new char[256];
memset(d, 0x77, 256);
+ check_ptr(d);
delete [] d;
EXPECT_EQUAL((int)d[0], 0x66);
EXPECT_EQUAL((int)d[1], 0x66);
@@ -44,6 +52,7 @@ void Test::testFillValue(char *a)
// Verify overwrite detection in place after cleaning up.
for (size_t i(0); i < sizeof(aa)/sizeof(aa[0]); i++) {
+ check_ptr(aa[i]);
delete [] aa[i];
EXPECT_EQUAL((int)a[0], 0x66);
EXPECT_EQUAL((int)a[1], 0x66);
@@ -55,6 +64,7 @@ void Test::verifyPreWriteDetection()
{
char * a = new char[8];
*(a-1) = 0;
+ check_ptr(a);
delete [] a;
}
@@ -62,6 +72,7 @@ void Test::verifyPostWriteDetection()
{
char * a = new char[8];
a[8] = 0;
+ check_ptr(a);
delete [] a;
}
@@ -69,9 +80,11 @@ void Test::verifyWriteAfterFreeDetection()
{
// Make sure that enough blocks of memory is allocated and freed.
char * a = new char[256];
+ check_ptr(a);
delete [] a;
for (size_t i(0); i < 100; i++) {
char *d = new char[256];
+ check_ptr(d);
delete [] d;
}
// Write freed memory.
@@ -85,6 +98,7 @@ void Test::verifyWriteAfterFreeDetection()
// Clean up.
for (size_t i(0); i < sizeof(aa)/sizeof(aa[0]); i++) {
+ check_ptr(aa[i]);
delete [] aa[i];
}
}
@@ -101,6 +115,7 @@ int Test::Main()
EXPECT_EQUAL((int)a[255], 0x77);
char * b = a;
EXPECT_EQUAL(a, b);
+ check_ptr(a);
delete [] a;
EXPECT_EQUAL(a, b);