|
From: <fa...@ca...> - 2004-07-12 21:52:27
|
I'm running across a mismatched new/delete error in stable_sort() from
the STL. I'm using valgrind 2.1.1, gcc 3.4.1 on RHEL 3.0 (glibc 2.3.2).
Is this a known error in valgrind or the gnu STL, or (more likely) am I
doing something stupid?
Thanks for the great program!
- Matt
A simple test program:
#include <vector>
#include <algorithm>=20
#include <functional>
#include <iostream>
int main(int argc, char* argv[])=20
{
std::vector<int> data;
for (int i=3D0;i<100;i++) data.push_back(i%7);
stable_sort( data.begin(), data.end() );
std::cout << data[50] << std::endl;
}
Results in the error:
=3D=3D27651=3D=3D Mismatched free() / delete / delete []
=3D=3D27651=3D=3D at 0x3C01E87B: free (vg_replace_malloc.c:127)
=3D=3D27651=3D=3D by 0x3C0C78D0: operator delete(void*, std::nothrow_t
const&) (del_opnt.cc:39)
=3D=3D27651=3D=3D by 0x8049758: void std::return_temporary_buffer<int>(i=
nt*)
(memory:122)
=3D=3D27651=3D=3D by 0x80492E2:
std::_Temporary_buffer<__gnu_cxx::__normal_iterator<int*,
std::vector<int, std::allocator<int> > >, int>::~_Temporary_buffer()
(stl_tempbuf.h:129)
=3D=3D27651=3D=3D Address 0x3C2705A0 is 0 bytes inside a block of size 400=
alloc'd
=3D=3D27651=3D=3D at 0x3C01E5B6: operator new(unsigned, std::nothrow_t
const&) (vg_replace_malloc.c:110)
=3D=3D27651=3D=3D by 0x8049F37: std::pair<int*, int>
std::__get_temporary_buffer<int>(int, int*) (memory:81)
=3D=3D27651=3D=3D by 0x804972C: std::pair<int*, int>
std::get_temporary_buffer<int>(int) (memory:110)
=3D=3D27651=3D=3D by 0x804921B:
std::_Temporary_buffer<__gnu_cxx::__normal_iterator<int*,
std::vector<int, std::allocator<int> > >,
int>::_Temporary_buffer(__gnu_cxx::__normal_iterator<int*,
std::vector<int, std::allocator<int> > >,
__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int>
> >) (stl_tempbuf.h:153)
|
|
From: Nicholas N. <nj...@ca...> - 2004-07-13 13:29:56
|
On Mon, 12 Jul 2004 fa...@ca... wrote:
> Is this a known error in valgrind or the gnu STL, or (more likely) am I
> doing something stupid?
>
> A simple test program:
>
> #include <vector>
> #include <algorithm>
> #include <functional>
> #include <iostream>
>
> int main(int argc, char* argv[])
> {
> std::vector<int> data;
> for (int i=0;i<100;i++) data.push_back(i%7);
> stable_sort( data.begin(), data.end() );
> std::cout << data[50] << std::endl;
> }
>
>
> Results in the error:
>
> ==27651== Mismatched free() / delete / delete []
> ==27651== at 0x3C01E87B: free (vg_replace_malloc.c:127)
> ==27651== by 0x3C0C78D0: operator delete(void*, std::nothrow_t
> const&) (del_opnt.cc:39)
Looks like a Valgrind bug. It's not catching replacing delete(nothrow)
with its own version.
To fix this requires knowing what the mangled name of delete(nothrow) is,
but I don't know how to work this out... the one for new(nothrow) is
_ZnwjRKSt9nothrow_t... maybe someone else can enlighten me.
N
|
|
From: Tom H. <th...@cy...> - 2004-07-13 13:43:47
|
In message <Pin...@he...>
Nicholas Nethercote <nj...@ca...> wrote:
> Looks like a Valgrind bug. It's not catching replacing
> delete(nothrow) with its own version.
>
> To fix this requires knowing what the mangled name of delete(nothrow)
> is, but I don't know how to work this out... the one for new(nothrow)
> is _ZnwjRKSt9nothrow_t... maybe someone else can enlighten me.
A bit of playing with nm and c++filt on libstdc++.so suggests this:
_ZdaPvRKSt9nothrow_t operator delete[](void*, std::nothrow_t const&)
_ZdlPvRKSt9nothrow_t operator delete(void*, std::nothrow_t const&)
_ZnwjRKSt9nothrow_t operator new(unsigned, std::nothrow_t const&)
_ZnajRKSt9nothrow_t operator new[](unsigned, std::nothrow_t const&)
Tom
--
Tom Hughes (th...@cy...)
Software Engineer, Cyberscience Corporation
http://www.cyberscience.com/
|
|
From: Nicholas N. <nj...@ca...> - 2004-07-14 12:39:25
Attachments:
diff
|
On Tue, 13 Jul 2004, Nicholas Nethercote wrote: >> Results in the error: >> >> ==27651== Mismatched free() / delete / delete [] >> ==27651== at 0x3C01E87B: free (vg_replace_malloc.c:127) >> ==27651== by 0x3C0C78D0: operator delete(void*, std::nothrow_t >> const&) (del_opnt.cc:39) > > Looks like a Valgrind bug. It's not catching replacing delete(nothrow) with > its own version. > > To fix this requires knowing what the mangled name of delete(nothrow) is, but > I don't know how to work this out... the one for new(nothrow) is > _ZnwjRKSt9nothrow_t... maybe someone else can enlighten me. Can you try the attached patch against the current Valgrind CVS HEAD? (See valgrind.kde.org/cvs.html for how to obtain/build the CVS HEAD.) If the patch works, I will commit it. Thanks for your help. N |