Boost C++ Libraries: Ticket #2048: exception when I create boost::RegEx in destructor code flow https://svn.boost.org/trac10/ticket/2048 <p> Hello! I use VC++ 2005 (sp1), boost 1_35_0 See <strong> line. I have an exception at this point. </strong></p> <p> This function (CTradeHourScheduler::<a class="missing wiki">IniFileName</a>()) is used many time in my code. No any errors while programm init or while I use boost::<a class="missing wiki">RegEx</a> in a programm flow. </p> <p> But, I see an exception when I create boost::<a class="missing wiki">RegEx</a> 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::<a class="missing wiki">RegEx</a> in destructon? Thank you! </p> <p> Boris. </p> <p> CString CTradeHourScheduler::<a class="missing wiki">IniFileName</a>(){ </p> <blockquote> <p> TCHAR cTmpBuff<a class="changeset" href="https://svn.boost.org/trac10/changeset/2000" title="revamped reference ">[2000]</a>=<a class="missing report" title="report does not exist">{0}</a>; </p> </blockquote> <blockquote> <p> <a class="missing wiki">GetModuleFileName</a>(NULL,cTmpBuff,2000); CString sAppPath=cTmpBuff; </p> </blockquote> <blockquote> <p> boost::<a class="missing wiki">RegEx</a> Sometest; </p> </blockquote> <p> <strong> Sometest.<a class="missing wiki">SetExpression</a>(CT2A(_T("<sup>(.*)<br /><br />[</sup><br /><br />]+$"))); I have got an exception at this point while it is called from destructor <em> std::string </em></strong></p> <blockquote> <p> CString strAppDir; Sometest.Match(CT2A(cTmpBuff)); .... </p> </blockquote> <p> } </p> <p> Debugger call sack is here: </p> <blockquote> <p> TQServerII.exe!std::_Tree&lt;std::_Tmap_traits&lt;unsigned long,std::list&lt;std::pair&lt;boost::shared_ptr&lt;boost::re_detail::w32_regex_traits_implementation&lt;char&gt; const &gt;,unsigned long const *&gt;,std::allocator&lt;std::pair&lt;boost::shared_ptr&lt;boost::re_detail::w32_regex_traits_implementation&lt;char&gt; const &gt;,unsigned long const *&gt; &gt; &gt;::_Iterator&lt;1&gt;,std::less&lt;unsigned long&gt;,std::allocator&lt;std::pair&lt;unsigned long const ,std::list&lt;std::pair&lt;boost::shared_ptr&lt;boost::re_detail::w32_regex_traits_implementation&lt;char&gt; const &gt;,unsigned long const *&gt;,std::allocator&lt;std::pair&lt;boost::shared_ptr&lt;boost::re_detail::w32_regex_traits_implementation&lt;char&gt; const &gt;,unsigned long const *&gt; &gt; &gt;::_Iterator&lt;1&gt; &gt; &gt;,0&gt; &gt;::_Lbound(const unsigned long &amp; _Keyval=1049) Line 1170 + 0x8 bytes C++ TQServerII.exe!std::_Tree&lt;std::_Tmap_traits&lt;unsigned long,std::list&lt;std::pair&lt;boost::shared_ptr&lt;boost::re_detail::w32_regex_traits_implementation&lt;char&gt; const &gt;,unsigned long const *&gt;,std::allocator&lt;std::pair&lt;boost::shared_ptr&lt;boost::re_detail::w32_regex_traits_implementation&lt;char&gt; const &gt;,unsigned long const *&gt; &gt; &gt;::_Iterator&lt;1&gt;,std::less&lt;unsigned long&gt;,std::allocator&lt;std::pair&lt;unsigned long const ,std::list&lt;std::pair&lt;boost::shared_ptr&lt;boost::re_detail::w32_regex_traits_implementation&lt;char&gt; const &gt;,unsigned long const *&gt;,std::allocator&lt;std::pair&lt;boost::shared_ptr&lt;boost::re_detail::w32_regex_traits_implementation&lt;char&gt; const &gt;,unsigned long const *&gt; &gt; &gt;::_Iterator&lt;1&gt; &gt; &gt;,0&gt; &gt;::lower_bound(const unsigned long &amp; _Keyval=1049) Line 987 + 0x10 bytes C++ TQServerII.exe!std::_Tree&lt;std::_Tmap_traits&lt;unsigned long,std::list&lt;std::pair&lt;boost::shared_ptr&lt;boost::re_detail::w32_regex_traits_implementation&lt;char&gt; const &gt;,unsigned long const *&gt;,std::allocator&lt;std::pair&lt;boost::shared_ptr&lt;boost::re_detail::w32_regex_traits_implementation&lt;char&gt; const &gt;,unsigned long const *&gt; &gt; &gt;::_Iterator&lt;1&gt;,std::less&lt;unsigned long&gt;,std::allocator&lt;std::pair&lt;unsigned long const ,std::list&lt;std::pair&lt;boost::shared_ptr&lt;boost::re_detail::w32_regex_traits_implementation&lt;char&gt; const &gt;,unsigned long const *&gt;,std::allocator&lt;std::pair&lt;boost::shared_ptr&lt;boost::re_detail::w32_regex_traits_implementation&lt;char&gt; const &gt;,unsigned long const *&gt; &gt; &gt;::_Iterator&lt;1&gt; &gt; &gt;,0&gt; &gt;::find(const unsigned long &amp; _Keyval=1049) Line 961 + 0x10 bytes C++ TQServerII.exe!boost::object_cache&lt;unsigned long,boost::re_detail::w32_regex_traits_implementation&lt;char&gt; &gt;::do_get(const unsigned long &amp; k=1049, unsigned int max_cache_size=5) Line 92 + 0x12 bytes C++ </p> <blockquote class="citation"> <blockquote> <p> TQServerII.exe!boost::object_cache&lt;unsigned long,boost::re_detail::w32_regex_traits_implementation&lt;char&gt; &gt;::get(const unsigned long &amp; k=1049, unsigned int max_cache_size=5) Line 69 + 0x11 bytes C++ </p> </blockquote> </blockquote> <p> TQServerII.exe!boost::re_detail::create_w32_regex_traits&lt;char&gt;(unsigned long l=1049) Line 554 + 0xf bytes C++ TQServerII.exe!boost::w32_regex_traits&lt;char&gt;::w32_regex_traits&lt;char&gt;() Line 573 + 0x16 bytes C++ TQServerII.exe!boost::regex_traits&lt;char,boost::w32_regex_traits&lt;char&gt; &gt;::regex_traits&lt;char,boost::w32_regex_traits&lt;char&gt; &gt;() Line 75 + 0xf bytes C++ TQServerII.exe!boost::regex_traits_wrapper&lt;boost::regex_traits&lt;char,boost::w32_regex_traits&lt;char&gt; &gt; &gt;::regex_traits_wrapper&lt;boost::regex_traits&lt;char,boost::w32_regex_traits&lt;char&gt; &gt; &gt;() Line 169 + 0xf bytes C++ TQServerII.exe!boost::re_detail::regex_data&lt;char,boost::regex_traits&lt;char,boost::w32_regex_traits&lt;char&gt; &gt; &gt;::regex_data&lt;char,boost::regex_traits&lt;char,boost::w32_regex_traits&lt;char&gt; &gt; &gt;() Line 61 + 0x4a bytes C++ TQServerII.exe!boost::re_detail::basic_regex_implementation&lt;char,boost::regex_traits&lt;char,boost::w32_regex_traits&lt;char&gt; &gt; &gt;::basic_regex_implementation&lt;char,boost::regex_traits&lt;char,boost::w32_regex_traits&lt;char&gt; &gt; &gt;() Line 93 + 0xf bytes C++ TQServerII.exe!boost::basic_regex&lt;char,boost::regex_traits&lt;char,boost::w32_regex_traits&lt;char&gt; &gt; &gt;::do_assign(const char * p1=0x0012ede0, const char * p2=0x0012edee, unsigned int f=262144) Line 525 + 0x22 bytes C++ TQServerII.exe!boost::basic_regex&lt;char,boost::regex_traits&lt;char,boost::w32_regex_traits&lt;char&gt; &gt; &gt;::assign(const char * p1=0x0012ede0, const char * p2=0x0012edee, unsigned int f=262144) Line 263 C++ TQServerII.exe!boost::basic_regex&lt;char,boost::regex_traits&lt;char,boost::w32_regex_traits&lt;char&gt; &gt; &gt;::assign(const char * p=0x0012ede0, unsigned int f=262144) Line 248 C++ TQServerII.exe!boost::basic_regex&lt;char,boost::regex_traits&lt;char,boost::w32_regex_traits&lt;char&gt; &gt; &gt;::set_expression(const char * p=0x0012ede0, unsigned int f=0) Line 467 C++ TQServerII.exe!boost::RegEx::<a class="missing wiki">SetExpression</a>(const char * p=0x0012ede0, bool icase=false) Line 177 + 0x13 bytes C++ </p> </blockquote> <p> <strong>* TQServerII.exe!CTradeHourScheduler::<a class="missing wiki">IniFileName</a>() Line 81 + 0x3f bytes C++ </strong></p> <blockquote> <p> TQServerII.exe!CTradeHourScheduler::<a class="missing wiki">SaveData</a>() 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<em>() + 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] </em></p> </blockquote> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2048 Trac 1.4.3 Boris <boris_k@…> Wed, 25 Jun 2008 13:06:58 GMT attachment set https://svn.boost.org/trac10/ticket/2048 https://svn.boost.org/trac10/ticket/2048 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boostRegExquestion</span> </li> </ul> <p> Message and call stack at axception point. </p> Ticket John Maddock Fri, 11 Jul 2008 17:24:12 GMT status changed https://svn.boost.org/trac10/ticket/2048#comment:1 https://svn.boost.org/trac10/ticket/2048#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> Boris, I don't know how to answer this, as the answer would appear to depend upon the details of how MSVC implements destructors :-( </p> <p> 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. </p> <p> If you have a test case I can look at then I'll try and take a look, otherwise &lt;shrug&gt; I guess, don't know what to say really... </p> <p> John. </p> Ticket John Maddock Fri, 29 Aug 2008 10:16:21 GMT cc set https://svn.boost.org/trac10/ticket/2048#comment:2 https://svn.boost.org/trac10/ticket/2048#comment:2 <ul> <li><strong>cc</strong> <span class="trac-author">boris_k@…</span> added </li> </ul> <p> Any update or test case on this one? </p> <p> Thanks, John. </p> Ticket Boris <boris_k@…> Fri, 05 Sep 2008 14:22:00 GMT <link>https://svn.boost.org/trac10/ticket/2048#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2048#comment:3</guid> <description> <p> I can not provide u an stable error case now. </p> <p> I will as soon as I can. </p> <p> Some time I see error while I use boost::<a class="missing wiki">RegEx</a> but I can not reproduce an error in small sample project. I will keep you in touch. </p> <p> Thank you. Boris. </p> <p> PS Last error was when I had changed line boost::<a class="missing wiki">RegEx</a> Sometest("&lt;<a class="missing wiki">LoginRecord</a>&gt;.*&lt;<a class="missing wiki">/LoginRecord</a>&gt;"); to line boost::<a class="missing wiki">RegEx</a> Sometest(".*&lt;<a class="missing wiki">LoginRecord</a>&gt;.*&lt;<a class="missing wiki">/LoginRecord</a>&gt;"); </p> <p> But it works fine now and I can not reproduce this error now. </p> </description> <category>Ticket</category> </item> <item> <author>Boris <boris_k@…></author> <pubDate>Fri, 05 Sep 2008 14:44:06 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/2048 https://svn.boost.org/trac10/ticket/2048 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">callstack.txt</span> </li> </ul> <blockquote> <p> call stack for error while construct object </p> </blockquote> Ticket Boris <boris_k@…> Fri, 05 Sep 2008 15:22:28 GMT <link>https://svn.boost.org/trac10/ticket/2048#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2048#comment:4</guid> <description> <p> See <a class="ext-link" href="http://dashunia.futures.com.ua/tmp/RegExpTest.zip"><span class="icon">​</span>http://dashunia.futures.com.ua/tmp/RegExpTest.zip</a> for error case </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Fri, 12 Sep 2008 11:22:47 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2048#comment:5 https://svn.boost.org/trac10/ticket/2048#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> You're passing an invalid regular expression to boost::<a class="missing wiki">RegEx</a>: </p> <p> "*.&lt;<a class="missing wiki">LoginRecord</a>&gt;.*&lt;<a class="missing wiki">/LoginRecord</a>&gt;" </p> <p> should be: </p> <p> ".*&lt;<a class="missing wiki">LoginRecord</a>&gt;.*&lt;<a class="missing wiki">/LoginRecord</a>&gt;" </p> <p> The subsequent exception is deliberate: you've invalidated a precondition by calling .Match on an invalid regex. </p> <p> HTH, John. </p> Ticket Boris <boris_k@…> Mon, 15 Sep 2008 11:51:31 GMT <link>https://svn.boost.org/trac10/ticket/2048#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2048#comment:6</guid> <description> <p> Ooops! It was my fall!!!! Sorry. Thank you for your time and your work! </p> </description> <category>Ticket</category> </item> </channel> </rss>