From: Nicholas Nethercote Date: Thu, 9 Oct 2003 15:40:38 +0000 (+0000) Subject: Added interceptions for: X-Git-Tag: svn/VALGRIND_2_1_0~149 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e5cca0566e116307d33cd278e29119e51017d8fb;p=thirdparty%2Fvalgrind.git Added interceptions for: 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 --- diff --git a/coregrind/vg_replace_malloc.c b/coregrind/vg_replace_malloc.c index 9c3ca2560e..7e3d76ef87 100644 --- a/coregrind/vg_replace_malloc.c +++ b/coregrind/vg_replace_malloc.c @@ -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 index 0000000000..82e5bc5141 --- /dev/null +++ b/memcheck/tests/new_nothrow.cpp @@ -0,0 +1,13 @@ +#include + +// 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 index 0000000000..e69de29bb2 diff --git a/memcheck/tests/new_nothrow.vgtest b/memcheck/tests/new_nothrow.vgtest new file mode 100644 index 0000000000..ea8dda3cf7 --- /dev/null +++ b/memcheck/tests/new_nothrow.vgtest @@ -0,0 +1,2 @@ +prog: new_nothrow +vgopts: -q