Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#2048 closed Bugs (invalid)

exception when I create boost::RegEx in destructor code flow

Reported by: Boris <boris_k@…> Owned by: John Maddock
Milestone: To Be Determined Component: regex
Version: Boost 1.35.0 Severity: Problem
Keywords: exception SetExpression Cc: boris_k@…

Description

Hello! I use VC++ 2005 (sp1), boost 1_35_0 See line. I have an exception at this point.

This function (CTradeHourScheduler::IniFileName()) is used many time in my code. No any errors while programm init or while I use boost::RegEx in a programm flow.

But, I see an exception when I create boost::RegEx while destructuor of some object is called. "Unhandled exception at 0x00470301 in TQServerII.exe: 0xC0000005: Access violation reading location 0x00000004." No memory leek. When I disable this function call I see no memory leek too. Can I use boost::RegEx in destructon? Thank you!

Boris.

CString CTradeHourScheduler::IniFileName(){

TCHAR cTmpBuff[2000]={0};

GetModuleFileName(NULL,cTmpBuff,2000); CString sAppPath=cTmpBuff;

boost::RegEx Sometest;

Sometest.SetExpression(CT2A(_T("(.*)

[


]+$"))); I have got an exception at this point while it is called from destructor std::string

CString strAppDir; Sometest.Match(CT2A(cTmpBuff)); ....

}

Debugger call sack is here:

TQServerII.exe!std::_Tree<std::_Tmap_traits<unsigned long,std::list<std::pair<boost::shared_ptr<boost::re_detail::w32_regex_traits_implementation<char> const >,unsigned long const *>,std::allocator<std::pair<boost::shared_ptr<boost::re_detail::w32_regex_traits_implementation<char> const >,unsigned long const *> > >::_Iterator<1>,std::less<unsigned long>,std::allocator<std::pair<unsigned long const ,std::list<std::pair<boost::shared_ptr<boost::re_detail::w32_regex_traits_implementation<char> const >,unsigned long const *>,std::allocator<std::pair<boost::shared_ptr<boost::re_detail::w32_regex_traits_implementation<char> const >,unsigned long const *> > >::_Iterator<1> > >,0> >::_Lbound(const unsigned long & _Keyval=1049) Line 1170 + 0x8 bytes C++ TQServerII.exe!std::_Tree<std::_Tmap_traits<unsigned long,std::list<std::pair<boost::shared_ptr<boost::re_detail::w32_regex_traits_implementation<char> const >,unsigned long const *>,std::allocator<std::pair<boost::shared_ptr<boost::re_detail::w32_regex_traits_implementation<char> const >,unsigned long const *> > >::_Iterator<1>,std::less<unsigned long>,std::allocator<std::pair<unsigned long const ,std::list<std::pair<boost::shared_ptr<boost::re_detail::w32_regex_traits_implementation<char> const >,unsigned long const *>,std::allocator<std::pair<boost::shared_ptr<boost::re_detail::w32_regex_traits_implementation<char> const >,unsigned long const *> > >::_Iterator<1> > >,0> >::lower_bound(const unsigned long & _Keyval=1049) Line 987 + 0x10 bytes C++ TQServerII.exe!std::_Tree<std::_Tmap_traits<unsigned long,std::list<std::pair<boost::shared_ptr<boost::re_detail::w32_regex_traits_implementation<char> const >,unsigned long const *>,std::allocator<std::pair<boost::shared_ptr<boost::re_detail::w32_regex_traits_implementation<char> const >,unsigned long const *> > >::_Iterator<1>,std::less<unsigned long>,std::allocator<std::pair<unsigned long const ,std::list<std::pair<boost::shared_ptr<boost::re_detail::w32_regex_traits_implementation<char> const >,unsigned long const *>,std::allocator<std::pair<boost::shared_ptr<boost::re_detail::w32_regex_traits_implementation<char> const >,unsigned long const *> > >::_Iterator<1> > >,0> >::find(const unsigned long & _Keyval=1049) Line 961 + 0x10 bytes C++ TQServerII.exe!boost::object_cache<unsigned long,boost::re_detail::w32_regex_traits_implementation<char> >::do_get(const unsigned long & k=1049, unsigned int max_cache_size=5) Line 92 + 0x12 bytes C++

TQServerII.exe!boost::object_cache<unsigned long,boost::re_detail::w32_regex_traits_implementation<char> >::get(const unsigned long & k=1049, unsigned int max_cache_size=5) Line 69 + 0x11 bytes C++

TQServerII.exe!boost::re_detail::create_w32_regex_traits<char>(unsigned long l=1049) Line 554 + 0xf bytes C++ TQServerII.exe!boost::w32_regex_traits<char>::w32_regex_traits<char>() Line 573 + 0x16 bytes C++ TQServerII.exe!boost::regex_traits<char,boost::w32_regex_traits<char> >::regex_traits<char,boost::w32_regex_traits<char> >() Line 75 + 0xf bytes C++ TQServerII.exe!boost::regex_traits_wrapper<boost::regex_traits<char,boost::w32_regex_traits<char> > >::regex_traits_wrapper<boost::regex_traits<char,boost::w32_regex_traits<char> > >() Line 169 + 0xf bytes C++ TQServerII.exe!boost::re_detail::regex_data<char,boost::regex_traits<char,boost::w32_regex_traits<char> > >::regex_data<char,boost::regex_traits<char,boost::w32_regex_traits<char> > >() Line 61 + 0x4a bytes C++ TQServerII.exe!boost::re_detail::basic_regex_implementation<char,boost::regex_traits<char,boost::w32_regex_traits<char> > >::basic_regex_implementation<char,boost::regex_traits<char,boost::w32_regex_traits<char> > >() Line 93 + 0xf bytes C++ TQServerII.exe!boost::basic_regex<char,boost::regex_traits<char,boost::w32_regex_traits<char> > >::do_assign(const char * p1=0x0012ede0, const char * p2=0x0012edee, unsigned int f=262144) Line 525 + 0x22 bytes C++ TQServerII.exe!boost::basic_regex<char,boost::regex_traits<char,boost::w32_regex_traits<char> > >::assign(const char * p1=0x0012ede0, const char * p2=0x0012edee, unsigned int f=262144) Line 263 C++ TQServerII.exe!boost::basic_regex<char,boost::regex_traits<char,boost::w32_regex_traits<char> > >::assign(const char * p=0x0012ede0, unsigned int f=262144) Line 248 C++ TQServerII.exe!boost::basic_regex<char,boost::regex_traits<char,boost::w32_regex_traits<char> > >::set_expression(const char * p=0x0012ede0, unsigned int f=0) Line 467 C++ TQServerII.exe!boost::RegEx::SetExpression(const char * p=0x0012ede0, bool icase=false) Line 177 + 0x13 bytes C++

* TQServerII.exe!CTradeHourScheduler::IniFileName() Line 81 + 0x3f bytes C++

TQServerII.exe!CTradeHourScheduler::SaveData() Line 28 + 0xc bytes C++ TQServerII.exe!CTradeHourScheduler::~CTradeHourScheduler() Line 25 C++ TQServerII.exe!CTradeHourScheduler::`scalar deleting destructor'() + 0xf bytes C++ TQServerII.exe!CTQServerIIApp::~CTQServerIIApp() Line 104 + 0x22 bytes C++ TQServerII.exe!`dynamic atexit destructor for 'theApp() + 0xd bytes C++ msvcr80d.dll!doexit(int code=20, int quick=0, int retcaller=0) Line 553 C msvcr80d.dll!exit(int code=20) Line 398 + 0xd bytes C TQServerII.exe__tmainCRTStartup() Line 610 C TQServerII.exe!wWinMainCRTStartup() Line 414 C KERNEL32.DLL!7c4e87f5() [Frames below may be incorrect and/or missing, no symbols loaded for KERNEL32.DLL]

Attachments (2)

boostRegExquestion (6.2 KB ) - added by Boris <boris_k@…> 14 years ago.
Message and call stack at axception point.
callstack.txt (5.4 KB ) - added by Boris <boris_k@…> 14 years ago.
call stack for error while construct object

Download all attachments as: .zip

Change History (8)

by Boris <boris_k@…>, 14 years ago

Attachment: boostRegExquestion added

Message and call stack at axception point.

comment:1 by John Maddock, 14 years ago

Status: newassigned

Boris, I don't know how to answer this, as the answer would appear to depend upon the details of how MSVC implements destructors :-(

Personally, I think that this should work, although generally speaking, creating a new regex object during a destructor call seems like a bad idea anyway? Looking at the call stack the error appears to be somewhere inside the std lib code, so I don't really see how I can fix that.

If you have a test case I can look at then I'll try and take a look, otherwise <shrug> I guess, don't know what to say really...

John.

comment:2 by John Maddock, 14 years ago

Cc: boris_k@… added

Any update or test case on this one?

Thanks, John.

comment:3 by Boris <boris_k@…>, 14 years ago

I can not provide u an stable error case now.

I will as soon as I can.

Some time I see error while I use boost::RegEx but I can not reproduce an error in small sample project. I will keep you in touch.

Thank you. Boris.

PS Last error was when I had changed line boost::RegEx Sometest("<LoginRecord>.*</LoginRecord>"); to line boost::RegEx Sometest(".*<LoginRecord>.*</LoginRecord>");

But it works fine now and I can not reproduce this error now.

by Boris <boris_k@…>, 14 years ago

Attachment: callstack.txt added

call stack for error while construct object

comment:5 by John Maddock, 14 years ago

Resolution: invalid
Status: assignedclosed

You're passing an invalid regular expression to boost::RegEx:

"*.<LoginRecord>.*</LoginRecord>"

should be:

".*<LoginRecord>.*</LoginRecord>"

The subsequent exception is deliberate: you've invalidated a precondition by calling .Match on an invalid regex.

HTH, John.

comment:6 by Boris <boris_k@…>, 14 years ago

Ooops! It was my fall!!!! Sorry. Thank you for your time and your work!

Note: See TracTickets for help on using tickets.