|
From: Susan M. <baj...@ho...> - 2009-07-21 23:51:49
|
Hello, everyone! I am a bit mystified by a memory leak that valgrind is
reporting (I am easily mystified), and I thought I would quickly post to see
if anyone could help.
Valgrind reports:
==3471== Address 0x5803F74 is 0 bytes after a block of size 4 alloc'd
==3471== at 0x4A06019: operator new(unsigned long)
(vg_replace_malloc.c:167)
==3471== by 0x40885A: __gnu_cxx::new_allocator<int>::allocate(unsigned
long, void const*) (new_allocator.h:88)
==3471== by 0x408882: std::_Vector_base<int, std::allocator<int>
>::_M_allocate(unsigned long) (stl_vector.h:127)
==3471== by 0x408FD3: std::vector<int, std::allocator<int>
>::_M_insert_aux(__gnu_cxx::__normal_iterator<int*, std::vector<int,
std::allocator<int> > >, int const&) (vector.tcc:275)
==3471== by 0x409219: std::vector<int, std::allocator<int>
>::push_back(int const&) (stl_vector.h:610)
==3471== by 0x40376C: BranchDecomposition::isLeaf(int)
(BranchDecomposition.cpp:378)
In my code, I have a vector< vector<int>> leaves. I begin by doing a
leaves.resize(XX);
When I look in my BranchDecomposition.cpp file at line 378, I see:
(leaves[i]).push_back(i);
My intention was to idicate that the i-th node in my graph was above only
leaf i in my tree. My thinking was that I had allocated space for a
pointer to an empty vector<int>, and thus, by pushing i into the empty
vector, I was not doing anything improper.
Later, I clear this memory with the following:
for (size_t i = 0; i < leaves.size(); i++) {
(leaves[i]).clear();
}
leaves.clear();
I know I am being hopelessly naive somewhere, but I just don't see it.
Can anyone help?
Very best regards,
Susan
_________________________________________________________________
Windows Live™ Hotmail®: Search, add, and share the web’s latest sports videos. Check it out.
http://www.windowslive.com/Online/Hotmail/Campaign/QuickAdd?ocid=TXT_TAGLM_WL_QA_HM_sports_videos_072009&cat=sports |
|
From: Nicholas N. <n.n...@gm...> - 2009-07-22 00:55:04
|
On Wed, Jul 22, 2009 at 9:51 AM, Susan Margulies<baj...@ho...> wrote: > Hello, everyone! I am a bit mystified by a memory leak that valgrind is > reporting (I am easily mystified), and I thought I would quickly post to see > if anyone could help. > > Valgrind reports: > > ==3471== Address 0x5803F74 is 0 bytes after a block of size 4 alloc'd It's not a memory leak -- rather, you've gone one past the end of the heap block. Knowing this might make it easier to work out what's gone wrong. Nick |