Bug 58737

Summary: leak in std::regex_match
Product: gcc Reporter: larsbj
Component: libstdc++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P3    
Version: 4.9.0   
Target Milestone: 4.9.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2013-10-15 00:00:00
Attachments: small program showing the problem
output from valgrind

Description larsbj 2013-10-15 11:25:08 UTC
I have something that certainly looks like a memory leak.

g++ --version
g++ (GCC) 4.9.0 20131014 (experimental)

g++ -std=gnu++11 -O2 leak.cpp

If I increase the amount of looping the leak reports
increases linearly.

All output from valgrind below. It might be regex or it might be some
allocator issue, I have seen something with std::deque as well outside
any regex context. Not been able to reproduce though.
Comment 1 larsbj 2013-10-15 11:26:00 UTC
Created attachment 31011 [details]
small program showing the problem
Comment 2 larsbj 2013-10-15 11:27:09 UTC
Created attachment 31012 [details]
output from valgrind
Comment 3 Paolo Carlini 2013-10-15 14:50:38 UTC
Maybe:

Index: regex_executor.h
===================================================================
--- regex_executor.h    (revision 203587)
+++ regex_executor.h    (working copy)
@@ -155,6 +155,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       virtual bool
       _M_main() = 0;
 
+      virtual
+      ~_Executor() { }
+
       _BiIter         _M_current;
       const _BiIter   _M_begin;
       const _BiIter   _M_end;

Eh, eh ;) ;)
Comment 4 Tim Shen 2013-10-15 15:01:46 UTC
Author: timshen
Date: Tue Oct 15 15:01:44 2013
New Revision: 203610

URL: http://gcc.gnu.org/viewcvs?rev=203610&root=gcc&view=rev
Log:
2013-10-15  Tim Shen  <timshen91@gmail.com>

	PR libstdc++/58737
	* include/bits/regex_automaton.h (_Automaton<>::~_Automaton): Fix memory
	leak by adding it.
	* include/bits/regex_executor.h (_Executor<>::~_Executor): Likewise.

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/regex_automaton.h
    trunk/libstdc++-v3/include/bits/regex_executor.h
Comment 5 Paolo Carlini 2013-10-15 15:06:13 UTC
Fixed.