valgrind/memory leak question

B

bluekite2000

My program has a bunch of matrix objects, all of which were allocated
w/ new and deallocated w/ delete. When valgrind runs, it gives me all
these errors such as

invalid read of size...
Address 0x25BC5694 is 4 bytes after a block of size 160 alloc'd
==25239== at 0x25985639: operator new[](unsigned)
(vg_replace_malloc.c:138)

invalid write of size...
Address 0x25BC91B4 is 4 bytes after a block of size 40 alloc'd
==25239== at 0x25985639: operator new[](unsigned)
(vg_replace_malloc.c:138)

And when my program exits, similar errors occur
invalid read of size...
at 0x804AEA4: Matrix<std::complex<float> >::~Matrix() (matlib2.h:424)
==25239== by 0x804A08B: main (test2.cc:153)
==25239== Address 0x25BE5B40 is 0 bytes inside a block of size 8
free'd
==25239== at 0x25985AB5: operator delete[](void*)
(vg_replace_malloc.c:161)
....
No malloc'd blocks -- no leaks are possible.
The output of my program is correct however.
PS: I tried a bt on gdb and the cursor points to my matrix destructor's
function. But I dont understand what that means really.
Thanx for ur help.
 
C

Christoph Bartoschek

No malloc'd blocks -- no leaks are possible.
The output of my program is correct however.
PS: I tried a bt on gdb and the cursor points to my matrix destructor's
function. But I dont understand what that means really.
Thanx for ur help.


You seem to have Off-by-one errors:

int * array = new int[10];
if (array[10] == 0) array[10] = 10;


This would produce such an error. Valgrind gives you the location of the
invalid read/write and the location where the corresponding memory chunk
has been allocated.

Christoph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top