Bug 12438 - Memory leak in locale::combine()
Summary: Memory leak in locale::combine()
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: 3.3.3
Assignee: Paolo Carlini
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-09-29 08:27 UTC by Pétur Runólfsson
Modified: 2004-01-19 00:14 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2003-09-29 09:56:24


Attachments
Test case (315 bytes, text/plain)
2003-09-29 08:28 UTC, Pétur Runólfsson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pétur Runólfsson 2003-09-29 08:27:12 UTC
template<typename Facet>
locale locale::combine(locale l1, locale l2) const

leaks memory if an exception is thrown because Facet isn't found in l2.
Comment 1 Pétur Runólfsson 2003-09-29 08:28:40 UTC
Created attachment 4851 [details]
Test case
Comment 2 Pétur Runólfsson 2003-09-29 08:36:35 UTC
The signature of combine is of course

template<typename Facet>
locale locale::combine(const locale& l2) const

Comment 3 Paolo Carlini 2003-09-29 09:56:24 UTC
Confirmed. Seems easy to fix, now ;)
Comment 4 Paolo Carlini 2003-09-29 22:16:36 UTC
Hi Pétur. How many iterations do you think are necessary? I have tried up to
1000000 without an hard fail (disk thrashing, however).

Thanks, Paolo.
Comment 5 Pétur Runólfsson 2003-09-30 10:58:57 UTC
> How many iterations do you think are necessary? I have tried up to
> 1000000 without an hard fail (disk thrashing, however).

The program won't crash until it runs out of memory, which may take
a very long time.

There is a function named set_memory_limits() in testsuite_hooks.h.
Maybe you can use that to make the program run out of memory sooner?
I don't think we want tests that use all virtual memory in the system,
or that take several hours to run.
Comment 6 Paolo Carlini 2003-09-30 11:16:56 UTC
Thanks Pétur, I will make use of your suggestion!
Comment 7 GCC Commits 2003-09-30 13:45:04 UTC
Subject: Bug 12438

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	paolo@gcc.gnu.org	2003-09-30 13:45:00

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/bits: locale_facets.tcc locale_classes.h 
Added files:
	libstdc++-v3/testsuite/22_locale/locale/cons: 12438.cc 

Log message:
	2003-09-30  Paolo Carlini  <pcarlini@unitus.it>
	
	PR libstdc++/12438
	* include/bits/locale_facets.tcc (locale::combine): Don't
	leak memory if _M_replace_facet throws.
	* testsuite/22_locale/locale/cons/12438.cc: New, from the PR.
	
	* include/bits/locale_classes.h (locale::locale(const locale&,
	_Facet*)): Tweak, use consistently _M_remove_reference.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&r1=1.1977&r2=1.1978
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/locale_facets.tcc.diff?cvsroot=gcc&r1=1.112&r2=1.113
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/locale_classes.h.diff?cvsroot=gcc&r1=1.11&r2=1.12
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/locale/cons/12438.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 8 Andrew Pinski 2003-09-30 15:47:12 UTC
Fixed.
Comment 9 GCC Commits 2004-01-19 00:13:00 UTC
Subject: Bug 12438

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	paolo@gcc.gnu.org	2004-01-19 00:12:55

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/bits: locale_classes.h locale_facets.tcc 
	libstdc++-v3/src: locale.cc localename.cc 

Log message:
	2004-01-19  Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/12352
	PR libstdc++/12438
	* include/bits/locale_classes.h (locale::locale(const locale&,
	_Facet*)): Don't leak memory on exception.
	* include/bits/locale_facets.tcc (locale::combine(const locale&)):
	Likewise.
	* src/locale.cc (locale::locale(const char*)): Likewise.
	* src/localename.cc (locale::_Impl::~_Impl(),
	locale::_Impl::_Impl(const _Impl&, size_t),
	locale::_Impl::_Impl(const char*, size_t)): Likewise.
	(locale::_Impl::_M_replace_categories(const _Impl*, category):
	Tweak.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.1464.2.165&r2=1.1464.2.166
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/locale_classes.h.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.1.2.3&r2=1.1.2.4
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/locale_facets.tcc.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.82.4.14&r2=1.82.4.15
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/src/locale.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.72.2.4&r2=1.72.2.5
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/src/localename.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.33.2.4&r2=1.33.2.5