[Dune] memory leak?

Matteo Semplice matteo.semplice at unito.it
Sun Apr 22 22:23:42 CEST 2012


Hi,
I was seeing a memory leak in one of my codes and I reduced it to
this sample code. I get a similar output if I replace center() with
volume().

I can't believe there's a leak in calling any method from geometry(),
but I can't see what I am doing wrong... Any clue?

(Using dune 2.1, if that matters)

Matteo

=====file test.cc ====
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <dune/grid/common/scsgmapper.hh>
int main(){
typedef Dune::OneDGrid G;
G grid(8,0.0,1.0);
typedef Dune::LeafSingleCodimSingleGeomTypeMapper<G,0> M;
M mapper(grid);
typedef G::LeafGridView GridView;
typedef GridView::Codim<0>::Iterator LeafIterator;
GridView gridView = grid.leafView();
LeafIterator endit = gridView.end<0>();
for (LeafIterator it = gridView.begin<0>(); it!=endit; ++it)
{
const int index = mapper.map(*it);
std::cout << "x=" << it->geometry().center()
<< " i=" << index
<< std::endl;
}
return(0);
}
======end file=====

matteo at montebianco:~/ufficio/Ricerca/dune-fv/src$ make test
g++ -std=c++0x -DHAVE_CONFIG_H -I. -I.. -I/home/matteo/include
-I/home/matteo/include -I/usr/lib/openmpi/include
-I/usr/lib/openmpi/include/openmpi -pthread -DMPIPP_H -DENABLE_MPI=1
-I/home/matteo/include/ug/ug -DENABLE_UG -I/usr/include/alberta
-DALBERTA_DIM=1 -DENABLE_ALBERTA -I/usr/lib/openmpi/include
-I/usr/lib/openmpi/include/openmpi -pthread -DMPIPP_H -DENABLE_MPI=1
-I/home/matteo/include/alugrid1.50
-I/home/matteo/include/alugrid1.50/serial
-I/home/matteo/include/alugrid1.50/duneinterface -DENABLE_ALUGRID
-I/home/matteo/include/alugrid1.50/parallel -DGRIDDIM=1 -DWORLDDIM=1
-DONEDGRID -g -O2 -MT test-test.o -MD -MP -MF .deps/test-test.Tpo -c
-o test-test.o `test -f 'test.cc' || echo './'`test.cc
mv -f .deps/test-test.Tpo .deps/test-test.Po
/bin/bash ../libtool --tag=CXX --mode=link g++ -std=c++0x -g
-O2 -o test test-test.o -L/home/matteo/lib -ldunegrid
-L/home/matteo/lib -ldunecommon -L/home/matteo/lib -lalugrid -pthread
-L/usr/lib/openmpi/lib -lmpi -lopen-rte -lopen-pal -ldl
-Wl,--export-dynamic -lnsl -lutil -lm -ldl -L/home/matteo/lib
-ldunealbertagrid_1d -ldunegrid -L/usr/lib -lalberta_1d -L/usr/lib
-lalberta_util -L/home/matteo/lib -lugS2 -lugS3 -ldevS -pthread
-L/usr/lib/openmpi/lib -lmpi -lopen-rte -lopen-pal -ldl
-Wl,--export-dynamic -lnsl -lutil -lm -ldl -llapack -L/home/matteo/lib
-ldunegrid -L/home/matteo/lib -ldunecommon
libtool: link: g++ -std=c++0x -g -O2 -o test test-test.o -pthread
-Wl,--export-dynamic -pthread -Wl,--export-dynamic -L/home/matteo/lib
-L/usr/lib -L/usr/lib/openmpi/lib
/home/matteo/lib/libdunealbertagrid_1d.a
-L/home/matteo/dune2.1/dune-common-2.1.0/lib /usr/lib/libalberta_1d.so
-lGL -lX11 /usr/lib/libalberta_util.so -lblas /home/matteo/lib/libugS2.a
/home/matteo/lib/libugS3.a /home/matteo/lib/libdevS.a -lm -llapack
/home/matteo/lib/libdunegrid.a /home/matteo/lib/libalugrid.a -lmetis
-lmpi -lopen-rte -lopen-pal /usr/lib/openmpi/lib/libmpi.so
/usr/lib/openmpi/lib/libopen-rte.so /usr/lib/openmpi/lib/libopen-pal.so
-lnsl -lutil -ldl /home/matteo/lib/libdunecommon.a -pthread -Wl,-rpath
-Wl,/usr/lib/openmpi/lib -Wl,-rpath -Wl,/usr/lib/openmpi/lib
matteo at montebianco:~/ufficio/Ricerca/dune-fv/src$ valgrind
--leak-check=full ./test
==5321== Memcheck, a memory error detector
==5321== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==5321== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for
copyright info
==5321== Command: ./test
==5321==
x=0.0625 i=0
x=0.1875 i=1
x=0.3125 i=2
x=0.4375 i=3
x=0.5625 i=4
x=0.6875 i=5
x=0.8125 i=6
x=0.9375 i=7
==5321==
==5321== HEAP SUMMARY:
==5321== in use at exit: 104 bytes in 2 blocks
==5321== total heap usage: 67 allocs, 65 frees, 3,753 bytes allocated
==5321==
==5321== 52 bytes in 1 blocks are definitely lost in loss record 1 of 2
==5321== at 0x402471C: operator new(unsigned int)
(vg_replace_malloc.c:255)
==5321== by 0x8071592: T.12789 (genericreferenceelements.hh:345)
==5321== by 0x8071D87: main (genericreferenceelements.hh:614)
==5321==
==5321== 52 bytes in 1 blocks are definitely lost in loss record 2 of 2
==5321== at 0x402471C: operator new(unsigned int)
(vg_replace_malloc.c:255)
==5321== by 0x8071DC5: main (genericreferenceelements.hh:345)
==5321==
==5321== LEAK SUMMARY:
==5321== definitely lost: 104 bytes in 2 blocks
==5321== indirectly lost: 0 bytes in 0 blocks
==5321== possibly lost: 0 bytes in 0 blocks
==5321== still reachable: 0 bytes in 0 blocks
==5321== suppressed: 0 bytes in 0 blocks
==5321==
==5321== For counts of detected and suppressed errors, rerun with: -v
==5321== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 73 from 8)






More information about the Dune mailing list