Bug 58737 - leak in std::regex_match
Summary: leak in std::regex_match
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: 4.9.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-15 11:25 UTC by larsbj
Modified: 2013-10-15 15:06 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-10-15 00:00:00


Attachments
small program showing the problem (126 bytes, text/x-c++src)
2013-10-15 11:26 UTC, larsbj
Details
output from valgrind (1.23 KB, text/plain)
2013-10-15 11:27 UTC, larsbj
Details

Note You need to log in before you can comment on or make changes to this bug.
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.