User account creation filtered due to spam.

Bug 12438 - Memory leak in locale::combine()
Summary: Memory leak in locale::combine()
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
Depends on:
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

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

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 CVS Commits 2003-09-30 13:45:04 UTC
Subject: Bug 12438

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	2003-09-30 13:45:00

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/bits: locale_facets.tcc locale_classes.h 
Added files:

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


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

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

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

Log message:
	2004-01-19  Paolo Carlini  <>
	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&)):
	* src/ (locale::locale(const char*)): Likewise.
	* src/ (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):