|
From: Nicholas N. <nj...@ca...> - 2003-10-09 15:41:08
|
On Thu, 9 Oct 2003, Sven Verdoolaege wrote:
> I have a problem with valgrind reporting a mismatched free / delete /
> delete[]
>
> This is a small example:
> > cat testnew.cc
> #include <new>
>
> int main()
> {
> int * a = new (std::nothrow) int[5];
> delete [] a;
> }
>
> > valgrind ./testnew
> ==22317== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux.
> ==22317== Copyright (C) 2002-2003, and GNU GPL'd, by Julian Seward.
> ==22317== Using valgrind-20030725, a program supervision framework for x86-linux.
> ==22317== Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward.
> ==22317== Estimated CPU clock rate is 1343 MHz
> ==22317== For more details, rerun with: -v
> ==22317==
> ==22317== Mismatched free() / delete / delete []
> ==22317== at 0x4002BB42: __builtin_vec_delete (vg_replace_malloc.c:252)
> ==22317== by 0x4002BB6D: operator delete[](void*) (vg_replace_malloc.c:261)
> ==22317== by 0x804846B: main (in /home/skimo/obj/barvinok/testnew)
> ==22317== by 0x403599EC: __libc_start_main (in /lib/libc.so.6)
> ==22317== Address 0x414A60D4 is 0 bytes inside a block of size 20 alloc'd
> ==22317== at 0x4002B721: malloc (vg_replace_malloc.c:153)
> ==22317== by 0x402E7F9A: operator new(unsigned, std::nothrow_t const&) (../../../../../src/gcc-3.3.1/libstdc++-v3/libsupc++/new_opnt.cc:47)
> ==22317== by 0x402E8065: operator new[](unsigned, std::nothrow_t const&) (../../../../../src/gcc-3.3.1/libstdc++-v3/libsupc++/new_opvnt.cc:36)
> ==22317== by 0x8048457: main (in /home/skimo/obj/barvinok/testnew)
>
> Is this a bug in gcc or in my program ?
Neither; it's a problem with Valgrind. Valgrind should be overriding
'operator new[](unsigned, std::nothrow_t)'.
> Is there a work-around ?
I've just committed a fix to CVS HEAD. Grab it using the instructions in
README. Note that the SF.net CVS server is very unreliable, you might
need multiple attempts to check it out successfully.
N
|