summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralkondratenko@gmail.com <alkondratenko@gmail.com@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2013-03-11 19:24:49 +0000
committeralkondratenko@gmail.com <alkondratenko@gmail.com@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2013-03-11 19:24:49 +0000
commit6354e2c8cdaaaeffdfe7d5b347b125394e2d55fa (patch)
tree35271ac6cac1ee229a3d36333e0abbe0c1ec596f
parent7896dcb9db2375fcd1d8d19052985a12ad113ba9 (diff)
downloadgperftools-6354e2c8cdaaaeffdfe7d5b347b125394e2d55fa.tar.gz
issue-506: fixed bogus unit test failure
Looks like my version of GCC is aware that free(malloc(X)) is a no-op. So it optimizes that away completely ignoring simple fact that we're observing malloc hooks invocations. By adding check that malloc succeeded we force gcc to actually preserve that malloc call. git-svn-id: http://gperftools.googlecode.com/svn/trunk@208 6b5cf1ce-ec42-a296-1ba9-69fdba395a50
-rw-r--r--src/tests/malloc_extension_c_test.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/tests/malloc_extension_c_test.c b/src/tests/malloc_extension_c_test.c
index af0e0c1..6b8fda6 100644
--- a/src/tests/malloc_extension_c_test.c
+++ b/src/tests/malloc_extension_c_test.c
@@ -59,6 +59,16 @@ void TestDeleteHook(const void* ptr) {
g_delete_hook_calls++;
}
+static
+void *forced_malloc(size_t size)
+{
+ void *rv = malloc(size);
+ if (!rv) {
+ FAIL("malloc is not supposed to fail here");
+ }
+ return rv;
+}
+
void TestMallocHook(void) {
/* TODO(csilvers): figure out why we get:
* E0100 00:00:00.000000 7383 malloc_hook.cc:244] RAW: google_malloc section is missing, thus InHookCaller is broken!
@@ -78,8 +88,9 @@ void TestMallocHook(void) {
if (!MallocHook_AddDeleteHook(&TestDeleteHook)) {
FAIL("Failed to add delete hook");
}
- free(malloc(10));
- free(malloc(20));
+
+ free(forced_malloc(10));
+ free(forced_malloc(20));
if (g_new_hook_calls != 2) {
FAIL("Wrong number of calls to the new hook");
}