]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Added interceptions for:
authorNicholas Nethercote <njn@valgrind.org>
Thu, 9 Oct 2003 15:40:38 +0000 (15:40 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Thu, 9 Oct 2003 15:40:38 +0000 (15:40 +0000)
  operator new(unsigned, std::nothrow_t const&)
  operator new[](unsigned, std::nothrow_t const&)

because they weren't being intercepted, and called malloc(), which caused bogus
mismatch errors.

Added a regression test for it, too.

MERGE TO STABLE (although the change to vg_replace_malloc.c won't quite be a
cut and paste job, because of prior changes made to it in the head
but not the stable branch;  merge will still be easy, though)

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1899

coregrind/vg_replace_malloc.c
memcheck/tests/new_nothrow.cpp [new file with mode: 0644]
memcheck/tests/new_nothrow.stderr.exp [new file with mode: 0644]
memcheck/tests/new_nothrow.vgtest [new file with mode: 0644]

index 9c3ca2560e3474841cfe67c270c7819e4189d5d7..7e3d76ef87c8cf2dbece75f92d62fe438e809175 100644 (file)
@@ -160,11 +160,18 @@ void* fff ( Int n ) \
    MALLOC_TRACE(" = %p\n", v ); \
    return v; \
 }
-ALLOC( malloc,            SK_(malloc)            );
-ALLOC( __builtin_new,     SK_(__builtin_new)     );
-ALLOC( _Znwj,             SK_(__builtin_new)     );
-ALLOC( __builtin_vec_new, SK_(__builtin_vec_new) );
-ALLOC( _Znaj,             SK_(__builtin_vec_new) );
+ALLOC( malloc,              SK_(malloc)            );
+ALLOC( __builtin_new,       SK_(__builtin_new)     );
+ALLOC( _Znwj,               SK_(__builtin_new)     );
+
+// operator new(unsigned, std::nothrow_t const&)
+ALLOC( _ZnwjRKSt9nothrow_t, SK_(__builtin_new)     );
+
+ALLOC( __builtin_vec_new,   SK_(__builtin_vec_new) );
+ALLOC( _Znaj,               SK_(__builtin_vec_new) );
+
+// operator new[](unsigned, std::nothrow_t const&
+ALLOC( _ZnajRKSt9nothrow_t, SK_(__builtin_vec_new) );
 
 #define FREE(fff, vgfff) \
 void fff ( void* p ) \
diff --git a/memcheck/tests/new_nothrow.cpp b/memcheck/tests/new_nothrow.cpp
new file mode 100644 (file)
index 0000000..82e5bc5
--- /dev/null
@@ -0,0 +1,13 @@
+#include <new>
+
+// At one point, Valgrind wasn't overriding these 'nothrow' versions;  since
+// they call malloc(), the calls to 'delete' caused bogus mismatch errors.
+
+int main()
+{
+    int * a = new (std::nothrow) int;
+    int * b = new (std::nothrow) int[5];
+    delete    a;
+    delete [] b;
+}
+
diff --git a/memcheck/tests/new_nothrow.stderr.exp b/memcheck/tests/new_nothrow.stderr.exp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/memcheck/tests/new_nothrow.vgtest b/memcheck/tests/new_nothrow.vgtest
new file mode 100644 (file)
index 0000000..ea8dda3
--- /dev/null
@@ -0,0 +1,2 @@
+prog: new_nothrow
+vgopts: -q