[osg-users] OpenThread leak ?

Adam Coates acoates at stanford.edu
Tue Sep 25 12:13:36 PDT 2007


I looked into this a tad more;  it looks like it is indeed caused by
the thread not being detached.  I added the line:

    pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);

before the thread creation so that the thread will clean up
automatically.  This eliminates the memory leak.  This is a bad hack,
since it will break the join() and detach() functions.  However,
before I tried this, I tried calling join() and detach() on the Thread
object, but that only leads to a segfault (not sure why yet).

AC

On 9/24/07, Adam Coates <acoates at stanford.edu> wrote:
> I'm not sure if this is the source but it's a possible issue anyway:
>
> Neither detach() nor join() are called on the thread, and it looks
> like threads are created in the joinable state.  The thread package
> has to allocate some resources to the thread that are not
> automatically cleaned up when the thread exits (e.g., a place to hold
> its return value until another thread joins it).  The thread's owner
> should probably call join() to wait for the thread to finish, or
> detach() to specify that the library is allowed to free this data.
>
> AC
>
> On 9/24/07, Cedric Pinson <mornifle at plopbyte.net> wrote:
> > I have a leak but i don't know if it's justified or if it's a known
> > issue, i googled a little on internet,  and i did not find anything.
> > So i ask on the mailing before searching deeper.
> > For information i call the cancel method at the end of my program.
> >
> > ==18164== 152 bytes in 1 blocks are definitely lost in loss record 3 of 4
> > ==18164==    at 0x4020848: calloc (in
> > /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
> > ==18164==    by 0x4010568: allocate_dtv (in /lib/ld-2.5.so)
> > ==18164==    by 0x401060D: _dl_allocate_tls (in /lib/ld-2.5.so)
> > ==18164==    by 0x4F88A98: pthread_create@@GLIBC_2.1 (in
> > /lib/libpthread-2.5.so)
> > ==18164==    by 0x4D4A704: OpenThreads::Thread::start() (PThread.c++:624)
> > ==18164==    by 0x4D4A74A: OpenThreads::Thread::startThread()
> > (PThread.c++:642)
> > ==18164==    by 0x8068C42: markneting::MarkNeting::update()
> > (MarkNeting.cpp:219)
> > ==18164==    by 0x8057E39:
> > markneting::MyFixturetest_updateHelper::RunTest(UnitTest::TestResults&)
> > (test-MarkNeting.cpp:137)
> > ==18164==    by 0x80588DE:
> > markneting::TestMyFixturetest_update::RunImpl(UnitTest::TestResults&)
> > const (test-MarkNeting.cpp:124)
> > ==18164==    by 0x4D50FA3: UnitTest::Test::Run(UnitTest::TestResults&)
> > const (in /usr/lib/libunittest++.so.0.0.0)
> > ==18164==    by 0x4: ???
> > ==18164==    by 0x4F7EFF3: (within /lib/libc-2.5.so)
> >
> > I try with an osg example (osgtext), and it seems to have the same leak
> >
> > ==18217== 152 bytes in 1 blocks are possibly lost in loss record 20 of 33
> > ==18217==    at 0x4020848: calloc (in
> > /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
> > ==18217==    by 0x4010568: allocate_dtv (in /lib/ld-2.5.so)
> > ==18217==    by 0x401060D: _dl_allocate_tls (in /lib/ld-2.5.so)
> > ==18217==    by 0x450FA98: pthread_create@@GLIBC_2.1 (in
> > /lib/libpthread-2.5.so)
> > ==18217==    by 0x402834E: OpenThreads::Thread::start() (in
> > /home/mornifle/dev/tmp/osg-svn/OpenSceneGraph/lib/libOpenThreads.so.1.9.6)
> > ==18217==    by 0x402839C: OpenThreads::Thread::startThread() (in
> > /home/mornifle/dev/tmp/osg-svn/OpenSceneGraph/lib/libOpenThreads.so.1.9.6)
> > ==18217==    by 0x448D065: osgViewer::Viewer::startThreading() (in
> > /home/mornifle/dev/tmp/osg-svn/OpenSceneGraph/lib/libosgViewer.so.2.1.9)
> > ==18217==    by 0x448FED6: osgViewer::Viewer::setUpThreading() (in
> > /home/mornifle/dev/tmp/osg-svn/OpenSceneGraph/lib/libosgViewer.so.2.1.9)
> >
> > maybe it's just a valgrind mistake :) if someone has more informations
> >
> > --
> > +33 (0) 6 63 20 03 56  Cedric Pinson mailto:mornifle at plopbyte.net http://www.plopbyte.net
> >
> >
> > _______________________________________________
> > osg-users mailing list
> > osg-users at lists.openscenegraph.org
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >
>



More information about the osg-users mailing list