diff options
Diffstat (limited to 'src/tests/debugallocation_test.cc')
-rw-r--r-- | src/tests/debugallocation_test.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/tests/debugallocation_test.cc b/src/tests/debugallocation_test.cc index f4a8567..beeb4cf 100644 --- a/src/tests/debugallocation_test.cc +++ b/src/tests/debugallocation_test.cc @@ -33,6 +33,8 @@ #include <stdio.h> #include <stdlib.h> +#include <malloc.h> // for memalign +#include <string.h> // for memcmp #include <vector> #include "gperftools/malloc_extension.h" #include "base/logging.h" @@ -296,6 +298,22 @@ TEST(DebugAllocationTest, HugeAlloc) { #endif } +// based on test program contributed by mikesart@gmail.com aka +// mikesart@valvesoftware.com. See issue-464. +TEST(DebugAllocationTest, ReallocAfterMemalloc) { + char stuff[50]; + memset(stuff, 0x11, sizeof(stuff)); + void *p = memalign(16, sizeof(stuff)); + EXPECT_NE(p, NULL); + memcpy(stuff, p, sizeof(stuff)); + + p = realloc(p, sizeof(stuff) + 10); + EXPECT_NE(p, NULL); + + int rv = memcmp(stuff, p, sizeof(stuff)); + EXPECT_EQ(rv, 0); +} + 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 |