[odb-users] WTL + ODB / or maybe auto_ptr Exception: Invalid Address specified to RtlValidateHeap

Wayne Hackle hacklew at hotmail.com
Wed Mar 28 00:27:37 EDT 2012


it's not auto_ptr or any smart pointer's problem, as i have checked. It must be a conflict between WTL/MFC and ODB.
Sorry to have rushed the question out of panic, please help.

> From: hacklew at hotmail.com
> To: odb-users at codesynthesis.com
> Date: Wed, 28 Mar 2012 03:09:35 +0000
> Subject: [odb-users] WTL + ODB / or maybe auto_ptr Exception: Invalid Address specified to RtlValidateHeap
> 
> 
> Thanks but that doesn't work either.
> I used a new subject because I think the original one is misleading.
> 
> I am using ODB with a VS2008 WTL dialog program.
> All the code that works with a Console program, when used with the WTL one, gives this exception:HEAP[scheduler.exe]: Invalid Address specified to RtlValidateHeap
> and the stacktrace goes (possibly need to scroll all the way to the bottom where the bold lines are)
>  	msvcr90d.dll!_free_dbg_nolock(void * pUserData=0x00fd35d0, int nBlockUse=1)  行1317 + 0x9 字节	C++ 	msvcr90d.dll!_free_dbg(void * pUserData=0x00fd35d0, int nBlockUse=1)  行1258 + 0xd 字节	C++ 	msvcr90d.dll!operator delete(void * pUserData=0x00fd35d0)  行54 + 0x10 字节	C++ 	odb-mysql-d-1.8-vc9.dll!std::allocator<std::_Tree_nod<std::_Tmap_traits<type_info const *,odb::details::shared_ptr<odb::mysql::statements_base>,odb::details::type_info_comparator,std::allocator<std::pair<type_info const * const,odb::details::shared_ptr<odb::mysql::statements_base> > >,0> >::_Node>::deallocate(std::_Tree_nod<std::_Tmap_traits<type_info const *,odb::details::shared_ptr<odb::mysql::statements_base>,odb::details::type_info_comparator,std::allocator<std::pair<type_info const * const,odb::details::shared_ptr<odb::mysql::statements_base> > >,0> >::_Node * _Ptr=0x00fd35d0, unsigned int __formal=1)  行140 + 0x9 字节	C++ 	odb-mysql-d-1.8-vc9.dll!std::_Tree<std::_Tmap_traits<type_info const *,odb::!
>  details::shared_ptr<odb::mysql::statements_base>,odb::details::type_info_comparator,std::allocator<std::pair<type_info const * const,odb::details::shared_ptr<odb::mysql::statements_base> > >,0> >::_Erase(std::_Tree_nod<std::_Tmap_traits<type_info const *,odb::details::shared_ptr<odb::mysql::statements_base>,odb::details::type_info_comparator,std::allocator<std::pair<type_info const * const,odb::details::shared_ptr<odb::mysql::statements_base> > >,0> >::_Node * _Rootnode=0x00fd35d0)  行1173	C++ 	odb-mysql-d-1.8-vc9.dll!std::_Tree<std::_Tmap_traits<type_info const *,odb::details::shared_ptr<odb::mysql::statements_base>,odb::details::type_info_comparator,std::allocator<std::pair<type_info const * const,odb::details::shared_ptr<odb::mysql::statements_base> > >,0> >::clear()  行972	C++ 	odb-mysql-d-1.8-vc9.dll!std::_Tree<std::_Tmap_traits<type_info const *,odb::details::shared_ptr<odb::mysql::statements_base>,odb::details::type_info_comparator,std::allocator<std::pair<type_info !
>  const * const,odb::details::shared_ptr<odb::mysql::statements_base> > 
> 
> >,0> >::erase(std::_Tree<std::_Tmap_traits<type_info const *,odb::details::shared_ptr<odb::mysql::statements_base>,odb::details::type_info_comparator,std::allocator<std::pair<type_info const * const,odb::details::shared_ptr<odb::mysql::statements_base> > >,0> >::const_iterator _First=(0x005438ec class person `RTTI Type Descriptor' {_m_data=0x00000000 _m_d_name=0x005438f4 ".?AVperson@@" },{x_=0x00037af0 }), std::_Tree<std::_Tmap_traits<type_info const *,odb::details::shared_ptr<odb::mysql::statements_base>,odb::details::type_info_comparator,std::allocator<std::pair<type_info const * const,odb::details::shared_ptr<odb::mysql::statements_base> > >,0> >::const_iterator _Last=(0xcdcdcdcd {_m_data=??? _m_d_name=0xcdcdcdd5 <错误的指针> },{x_=0xcdcdcdcd }))  行938	C++ 	odb-mysql-d-1.8-vc9.dll!std::_Tree<std::_Tmap_traits<type_info const *,odb::details::shared_ptr<odb::mysql::statements_base>,odb::details::type_info_comparator,std::allocator<std::pair<type_info const * const,odb::det!
>  ails::shared_ptr<odb::mysql::statements_base> > >,0> >::_Tidy()  行1421 + 0xaa 字节	C++ 	odb-mysql-d-1.8-vc9.dll!std::_Tree<std::_Tmap_traits<type_info const *,odb::details::shared_ptr<odb::mysql::statements_base>,odb::details::type_info_comparator,std::allocator<std::pair<type_info const * const,odb::details::shared_ptr<odb::mysql::statements_base> > >,0> >::~_Tree<std::_Tmap_traits<type_info const *,odb::details::shared_ptr<odb::mysql::statements_base>,odb::details::type_info_comparator,std::allocator<std::pair<type_info const * const,odb::details::shared_ptr<odb::mysql::statements_base> > >,0> >()  行541	C++ 	odb-mysql-d-1.8-vc9.dll!std::map<type_info const *,odb::details::shared_ptr<odb::mysql::statements_base>,odb::details::type_info_comparator,std::allocator<std::pair<type_info const * const,odb::details::shared_ptr<odb::mysql::statements_base> > > >::~map<type_info const *,odb::details::shared_ptr<odb::mysql::statements_base>,odb::details::type_info_comparator,std::a!
>  llocator<std::pair<type_info const * const,odb::details::shared_ptr<od
> 
> b::mysql::statements_base> > > >()  + 0x2b 字节	C++ 	odb-mysql-d-1.8-vc9.dll!odb::mysql::statement_cache::~statement_cache()  + 0x2e 字节	C++ 	odb-mysql-d-1.8-vc9.dll!odb::mysql::statement_cache::`scalar deleting destructor'()  + 0x2b 字节	C++ 	odb-mysql-d-1.8-vc9.dll!std::auto_ptr<odb::mysql::statement_cache>::~auto_ptr<odb::mysql::statement_cache>()  行718 + 0x2d 字节	C++ 	odb-mysql-d-1.8-vc9.dll!odb::mysql::connection::~connection()  行86 + 0x24 字节	C++ 	odb-mysql-d-1.8-vc9.dll!odb::mysql::connection_pool_factory::pooled_connection::~pooled_connection()  + 0x2b 字节	C++ 	odb-mysql-d-1.8-vc9.dll!odb::mysql::connection_pool_factory::pooled_connection::`scalar deleting destructor'()  + 0x2b 字节	C++ 	odb-mysql-d-1.8-vc9.dll!odb::details::bits::counter_ops<odb::details::shared_base,odb::mysql::connection_pool_factory::pooled_connection>::dec(odb::mysql::connection_pool_factory::pooled_connection * p=0x000375e0)  行172 + 0x35 字节	C++ 	odb-mysql-d-1.8-vc9.dll!odb::details::sh!
>  ared_ptr<odb::mysql::connection_pool_factory::pooled_connection>::~shared_ptr<odb::mysql::connection_pool_factory::pooled_connection>()  行27	C++ 	odb-mysql-d-1.8-vc9.dll!odb::details::shared_ptr<odb::mysql::connection_pool_factory::pooled_connection>::`scalar deleting destructor'()  + 0x2b 字节	C++ 	odb-mysql-d-1.8-vc9.dll!std::_Destroy<odb::details::shared_ptr<odb::mysql::connection_pool_factory::pooled_connection> >(odb::details::shared_ptr<odb::mysql::connection_pool_factory::pooled_connection> * _Ptr=0x000382c8)  行60	C++ 	odb-mysql-d-1.8-vc9.dll!std::allocator<odb::details::shared_ptr<odb::mysql::connection_pool_factory::pooled_connection> >::destroy(odb::details::shared_ptr<odb::mysql::connection_pool_factory::pooled_connection> * _Ptr=0x000382c8)  行160 + 0x9 字节	C++ 	odb-mysql-d-1.8-vc9.dll!std::_Destroy_range<std::allocator<odb::details::shared_ptr<odb::mysql::connection_pool_factory::pooled_connection> > >(odb::details::shared_ptr<odb::mysql::connection_pool_fac!
>  tory::pooled_connection> * _First=0x000382c8, odb::details::shared_ptr
> 
> <odb::mysql::connection_pool_factory::pooled_connection> * _Last=0x000382cc, std::allocator<odb::details::shared_ptr<odb::mysql::connection_pool_factory::pooled_connection> > & _Al={...}, std::_Nonscalar_ptr_iterator_tag __formal={...})  行234 + 0xc 字节	C++ 	odb-mysql-d-1.8-vc9.dll!std::_Destroy_range<std::allocator<odb::details::shared_ptr<odb::mysql::connection_pool_factory::pooled_connection> > >(odb::details::shared_ptr<odb::mysql::connection_pool_factory::pooled_connection> * _First=0x000382c8, odb::details::shared_ptr<odb::mysql::connection_pool_factory::pooled_connection> * _Last=0x000382cc, std::allocator<odb::details::shared_ptr<odb::mysql::connection_pool_factory::pooled_connection> > & _Al={...})  行225 + 0x2f 字节	C++ 	odb-mysql-d-1.8-vc9.dll!std::vector<odb::details::shared_ptr<odb::mysql::connection_pool_factory::pooled_connection>,std::allocator<odb::details::shared_ptr<odb::mysql::connection_pool_factory::pooled_connection> > >::_Destroy(odb::details::shared!
>  _ptr<odb::mysql::connection_pool_factory::pooled_connection> * _First=0x000382c8, odb::details::shared_ptr<odb::mysql::connection_pool_factory::pooled_connection> * _Last=0x000382cc)  行1124 + 0x14 字节	C++ 	odb-mysql-d-1.8-vc9.dll!std::vector<odb::details::shared_ptr<odb::mysql::connection_pool_factory::pooled_connection>,std::allocator<odb::details::shared_ptr<odb::mysql::connection_pool_factory::pooled_connection> > >::_Tidy()  行1137	C++ 	odb-mysql-d-1.8-vc9.dll!std::vector<odb::details::shared_ptr<odb::mysql::connection_pool_factory::pooled_connection>,std::allocator<odb::details::shared_ptr<odb::mysql::connection_pool_factory::pooled_connection> > >::~vector<odb::details::shared_ptr<odb::mysql::connection_pool_factory::pooled_connection>,std::allocator<odb::details::shared_ptr<odb::mysql::connection_pool_factory::pooled_connection> > >()  行560	C++ 	odb-mysql-d-1.8-vc9.dll!odb::mysql::connection_pool_factory::~connection_pool_factory()  行170 + 0x57 字节	C++ 	odb-mysq!
>  l-d-1.8-vc9.dll!odb::mysql::connection_pool_factory::`vector deleting 
> 
> destructor'()  + 0x69 字节	C++ 	odb-mysql-d-1.8-vc9.dll!std::auto_ptr<odb::mysql::connection_factory>::~auto_ptr<odb::mysql::connection_factory>()  行718 + 0x37 字节	C++ 	odb-mysql-d-1.8-vc9.dll!odb::mysql::database::~database()  行23 + 0xe 字节	C++ 	scheduler.exe!odb::mysql::database::`scalar deleting destructor'()  + 0x2e 字节	C++ 	scheduler.exe!std::auto_ptr<odb::database>::~auto_ptr<odb::database>()  行718 + 0x36 字节	C++
> Would it be a known issue with WTL? Or it seems more likely that it's about auto_ptr destructor?
> I googled googled and googled and no luck.
> Any help is appreciated.
> Hackle
> 
> > Date: Tue, 27 Mar 2012 15:28:58 +0200
> > From: boris at codesynthesis.com
> > To: hacklew at hotmail.com
> > CC: odb-users at codesynthesis.com
> > Subject: Re: [odb-users] What is the proper practice in using smart pointer	in querying
> > 
> > Hi Wayne,
> > 
> > Wayne Hackle <hacklew at hotmail.com> writes:
> > 
> > > The new question is: what is the proper practice in using shared_ptr 
> > > as default pointer? I ran into very annoying errors that indicate memory
> > > management fault (destructors especially).
> > > Here is my code:
> > >
> > > [...]
> > 
> > I don't see anything "illegal" in your code itself (though I don't
> > know what the person class looks like). The only problematic part
> > is vector<person>. You probably want to store shared pointers there
> > instead of copies of the objects. I would also move the session
> > closer to where it is actually needed:
> > 
> > auto_ptr<odb::database> db(
> >   new odb::mysql::database("root",
> >                            "somepassword",
> >                            "somedatabase",
> >                            "localhost"));
> > 
> > vector<shared_ptr<person> > v_person;
> > 
> > {
> >   session s;
> >   transaction t(db->begin());
> > 
> >   result<person> r(db->query<person>());
> >   for (result<person>::iterator i(r.begin()); i != r.end(); ++i)
> >   {	
> >     shared_ptr<person> p(i.load());
> >     v_person.push_back(p);
> >   }
> > 
> >   t.commit();
> > }
> > 
> > Boris
>  		 	   		  
 		 	   		  


More information about the odb-users mailing list