Boost logo

Boost Users :

Subject: Re: [Boost-users] boost wave memory leak
From: Rob Conde (rob.conde_at_[hidden])
Date: 2012-10-23 09:52:31


Sorry - should have provided more details...so here we go:

Visual Studio 2010 sp1
Boost 1.51
Linking to dlls

boost_xxxx-vc100-mt-gd-1_51.lib/dll

When running the following code I get:

Detected memory leaks!
Dumping objects ->
{276} normal block at 0x00358360, 392 bytes long.
 Data: <l 5 ` 5 x 5 > 6C 83 35 00 60 83 35 00 CD CD CD CD 78 83 35 00
{275} normal block at 0x003553F8, 264 bytes long.
 Data: < T5 T5 > 00 54 35 00 00 00 00 00 08 54 35 00 00 00 00 00
Object dump complete.

on standard out. Interestingly in my real usage case I only saw the 392 byte
leak. You can set the breakpoints in AllocHook to get the call stack. You
may need to change the request number on your machine...just run it once to
get the allocation numbers to use. Let me know if you need any more details.

#include <crtdbg.h>
#include <Windows.h>
#include <string>

#include <boost/wave.hpp>
#include <boost/wave/cpplexer/cpp_lex_token.hpp> // token class
#include <boost/wave/cpplexer/cpp_lex_iterator.hpp> // lexer class

int AllocHook( int allocType,
               void *userData,
               size_t size,
               int blockType,
               long requestNumber,
               const unsigned char *filename,
               int lineNumber);

class SetupMemLeakDetection
{
public:
   SetupMemLeakDetection()
   {
      int tmpDbgFlag;
      tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);

      _CrtSetAllocHook(AllocHook);

      tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF;
      _CrtSetDbgFlag(tmpDbgFlag);

      _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG
);
      _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
      _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG
);
      _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
      _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG
);
      _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );
   }
};

SetupMemLeakDetection smld;

int main(int argc, char * argv[])
{
   return 0;
}

int AllocHook( int allocType,
               void *userData,
               size_t size,
               int blockType,
               long requestNumber,
               const unsigned char *filename,
               int lineNumber)
{
   if(requestNumber == 275 && size == 264)
   {
      int five = 5;//put breakpoint here to get callstack
   }

   if(requestNumber == 276 && size == 392)
   {
      int five = 5;//put breakpoint here to get callstack
   }

   return TRUE;
}

//This code is never called, it just ensures the wave dll is linked
void waveFunctionality()
{
   typedef boost::wave::cpplexer::lex_token<> token_type;
   typedef boost::wave::cpplexer::lex_iterator<token_type>
lex_iterator_type;
   typedef boost::wave::context<std::string::iterator, lex_iterator_type>
context_type;

   boost::wave::util::file_position_type current_position;

   std::string instring;
   std::string filename;

   context_type ctx (instring.begin(), instring.end(), filename.c_str());

   context_type::iterator_type it = ctx.begin();
   context_type::iterator_type end = ctx.end();

   try
   {
      while (it != end) {
         current_position = (*it).get_position();

         if (*it == boost::wave::T_IDENTIFIER)
         {
         }
         else if(*it == boost::wave::T_STRINGLIT)
         {
         }
      }
   }
   catch(boost::wave::cpp_exception const & e)
   {
      std::string blah = e.file_name();
   }
}

-----Original Message-----
From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Hartmut Kaiser
Sent: Monday, October 22, 2012 8:00 PM
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] boost wave memory leak

> I'm getting a report of a memory leak when using boost wave. I see a
> similar problem at:
>
> https://svn.boost.org/trac/boost/ticket/4346
>
> but supposedly that is fixed for a while.
>
> The call stack is:

How did you get that call stack? What do I need to do to reproduce this
problem?

Regards Hartmut
---------------
http://boost-spirit.com
http://stellar.cct.lsu.edu

>
> MyDll.dll!operator new(unsigned int count, const std::nothrow_t &
> __formal)
> Line 18 + 0x9 bytes C++
>
> MyDll.dll!operator new[](unsigned int count, const std::nothrow_t & x)
> Line
> 15 + 0xd bytes C++
>
> MyDll.dll!boost::default_user_allocator_new_delete::malloc(const unsigned
> int bytes) Line 97 + 0xe bytes C++
>
> MyDll.dll!boost::pool<boost::default_user_allocator_new_delete>::mallo
> c_ne
> ed
> _resize() Line 693 + 0x9 bytes C++
>
> MyDll.dll!boost::pool<boost::default_user_allocator_new_delete>::malloc()
> Line 432 C++
>
> MyDll.dll!boost::singleton_pool<boost::fast_pool_allocator_tag,12,boos
> t::d
> ef
> ault_user_allocator_new_delete,boost::mutex,32,0>::malloc() Line 137
> + 0xb
> bytes C++
>
> MyDll.dll!boost::fast_pool_allocator<std::_List_nod<boost::wave::cpplexer:
> :l
> ex_token<boost::wave::util::file_position<boost::wave::util::flex_stri
> ng<c
> ha
> r,std::char_traits<char>,std::allocator<char>,boost::wave::util::CowSt
> ring
> <b
> oost::wave::util::AllocatorStringStorage<char,std::allocator<char>
> >,char *>
> > >
> >,boost::fast_pool_allocator<boost::wave::cpplexer::lex_token<boost::w
> >av
> >e::u
> til::file_position<boost::wave::util::flex_string<char,std::char_trait
> s<ch
> ar
> >,std::allocator<char>,boost::wave::util::CowString<boost::wave::util:
> >:A
> >lloc
> atorStringStorage<char,std::allocator<char> >,char *> > >
> >,boost::default_user_allocator_new_delete,boost::mutex,32,0>
> >::_Node,boost::default_user_allocator_new_delete,boost::mutex,32,0>::
> >al
> >loca
> te(const unsigned int n) Line 419 + 0xb bytes C++
>
> MyDll.dll!std::list<boost::wave::cpplexer::lex_token<boost::wave::util
> ::fi
> le
> _position<boost::wave::util::flex_string<char,std::char_traits<char>,std::
> al
> locator<char>,boost::wave::util::CowString<boost::wave::util::Allocato
> rStr
> in
> gStorage<char,std::allocator<char> >,char *> > >
> >,boost::fast_pool_allocator<boost::wave::cpplexer::lex_token<boost::w
> >av
> >e::u
> til::file_position<boost::wave::util::flex_string<char,std::char_trait
> s<ch
> ar
> >,std::allocator<char>,boost::wave::util::CowString<boost::wave::util:
> >:A
> >lloc
> atorStringStorage<char,std::allocator<char> >,char *> > >
> >,boost::default_user_allocator_new_delete,boost::mutex,32,0>
> >>::_Buynode()
> Line 1172 + 0x7 bytes C++
>
> MyDll.dll!std::list<boost::wave::cpplexer::lex_token<boost::wave::util
> ::fi
> le
> _position<boost::wave::util::flex_string<char,std::char_traits<char>,std::
> al
> locator<char>,boost::wave::util::CowString<boost::wave::util::Allocato
> rStr
> in
> gStorage<char,std::allocator<char> >,char *> > >
> >,boost::fast_pool_allocator<boost::wave::cpplexer::lex_token<boost::w
> >av
> >e::u
> til::file_position<boost::wave::util::flex_string<char,std::char_trait
> s<ch
> ar
> >,std::allocator<char>,boost::wave::util::CowString<boost::wave::util:
> >:A
> >lloc
> atorStringStorage<char,std::allocator<char> >,char *> > >
> >,boost::default_user_allocator_new_delete,boost::mutex,32,0>
> >::list<boost::wave::cpplexer::lex_token<boost::wave::util::file_posit
> >io
> >n<bo
> ost::wave::util::flex_string<char,std::char_traits<char>,std::allocato
> r<ch
> ar
> >,boost::wave::util::CowString<boost::wave::util::AllocatorStringStora
> >ge
> ><cha
> r,std::allocator<char> >,char *> > >
> >,boost::fast_pool_allocator<boost::wave::cpplexer::lex_token<boost::w
> >av
> >e::u
> til::file_position<boost::wave::util::flex_string<char,std::char_trait
> s<ch
> ar
> >,std::allocator<char>,boost::wave::util::CowString<boost::wave::util:
> >:A
> >lloc
> atorStringStorage<char,std::allocator<char> >,char *> > >
> >,boost::default_user_allocator_new_delete,boost::mutex,32,0> >()
> >Line
> >436
> + 0x68 bytes C++
>
> MyDll.dll!`dynamic initializer for
> 'boost::wave::util::impl::gen_unput_queue_iterator<boost::wave::cpplexer::
> le
> x_iterator<boost::wave::cpplexer::lex_token<boost::wave::util::file_po
> siti
> on
> <boost::wave::util::flex_string<char,std::char_traits<char>,std::alloc
> ator
> <c
> har>,boost::wave::util::CowString<boost::wave::util::AllocatorStringSt
> har>or
> har>age<
> char,std::allocator<char> >,char *> > > >
> >,boost::wave::cpplexer::lex_token<boost::wave::util::file_position<bo
> >os
> >t::w
> ave::util::flex_string<char,std::char_traits<char>,std::allocator<char
> >,bo
> os
> t::wave::util::CowString<boost::wave::util::AllocatorStringStorage<cha
> r,st
> d:
> :allocator<char> >,char *> > >
> >,std::list<boost::wave::cpplexer::lex_token<boost::wave::util::file_p
> >os
> >itio
> n<boost::wave::util::flex_string<char,std::char_traits<char>,std::allo
> cato
> r<
> char>,boost::wave::util::CowString<boost::wave::util::AllocatorStringS
> char>to
> char>rage
> <char,std::allocator<char> >,char *> > >
> >,boost::fast_pool_allocator<boost::wave::cpplexer::lex_token<boost::w
> >av
> >e::u
> til::file_position<boost::wave::util::flex_string<char,std::char_trait
> s<ch
> ar
> >,std::allocator<char>,boost::wave::util::CowString<boost::wave::util:
> >:A
> >lloc
> atorStringStorage<char,std::allocator<char> >,char *> > >
> >,boost::default_user_allocator_new_delete,boost::mutex,32,0> >
> >>::last''()
> Line 155 + 0x28 bytes C++
>
> msvcr90d.dll!__initterm() + 0x1c bytes
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users

_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net