public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/12540] New: Memory leak in locale::locale(const char*)
@ 2003-10-08 12:22 peturr02 at ru dot is
  2003-10-08 12:25 ` [Bug libstdc++/12540] " peturr02 at ru dot is
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: peturr02 at ru dot is @ 2003-10-08 12:22 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12540

           Summary: Memory leak in locale::locale(const char*)
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: peturr02 at ru dot is
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu

There is a memory leak in the constructor locale::locale(const char*).
The string allocated with strdup in the following snippet is leaked
under some conditions.

                // LANG may set a default different from "C".
                char* __env = std::getenv("LANG");
                if (!__env || std::strcmp(__env, "") == 0 
                    || std::strcmp(__env, "C") == 0 
                    || std::strcmp(__env, "POSIX") == 0)
                  __res = strdup("C");
                else 
                  __res = strdup(__env);

[...]

                      }
                    __str.erase(__str.end() - 1);
                    _M_impl = new _Impl(__str.c_str(), 1);
                  }
                // ... otherwise either an additional instance of
                // the "C" locale or LANG.
                else if (std::strcmp(__res, "C") == 0)
                  (_M_impl = _S_classic)->_M_add_reference();
                else
                  _M_impl = new _Impl(__res, 1);
                std::free(__res);

The leak occurs if the calls to locale::_Impl::_Impl throws an exception,
in that case free isn't called.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/12540] Memory leak in locale::locale(const char*)
  2003-10-08 12:22 [Bug libstdc++/12540] New: Memory leak in locale::locale(const char*) peturr02 at ru dot is
@ 2003-10-08 12:25 ` peturr02 at ru dot is
  2003-10-08 12:26 ` peturr02 at ru dot is
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: peturr02 at ru dot is @ 2003-10-08 12:25 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12540



------- Additional Comments From peturr02 at ru dot is  2003-10-08 12:25 -------
Created an attachment (id=4901)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=4901&action=view)
Test case

This is the test case from PR 12352. Note that it leaks very slowly,
so a large value of iters must used to detect it.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/12540] Memory leak in locale::locale(const char*)
  2003-10-08 12:22 [Bug libstdc++/12540] New: Memory leak in locale::locale(const char*) peturr02 at ru dot is
  2003-10-08 12:25 ` [Bug libstdc++/12540] " peturr02 at ru dot is
@ 2003-10-08 12:26 ` peturr02 at ru dot is
  2003-10-08 13:08 ` paolo at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: peturr02 at ru dot is @ 2003-10-08 12:26 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12540



------- Additional Comments From peturr02 at ru dot is  2003-10-08 12:26 -------
Also note that to get the leak, LC_ALL must not be set in the environment
and LANG must not be C.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/12540] Memory leak in locale::locale(const char*)
  2003-10-08 12:22 [Bug libstdc++/12540] New: Memory leak in locale::locale(const char*) peturr02 at ru dot is
  2003-10-08 12:25 ` [Bug libstdc++/12540] " peturr02 at ru dot is
  2003-10-08 12:26 ` peturr02 at ru dot is
@ 2003-10-08 13:08 ` paolo at gcc dot gnu dot org
  2003-10-16 17:24 ` cvs-commit at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: paolo at gcc dot gnu dot org @ 2003-10-08 13:08 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12540


paolo at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |paolo at gcc dot gnu dot org
                   |dot org                     |
             Status|UNCONFIRMED                 |ASSIGNED


------- Additional Comments From paolo at gcc dot gnu dot org  2003-10-08 13:08 -------
Ok, thanks. I had already noticed that more work was needed in this area...
probably this is *not* the last problem, unfortunately.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/12540] Memory leak in locale::locale(const char*)
  2003-10-08 12:22 [Bug libstdc++/12540] New: Memory leak in locale::locale(const char*) peturr02 at ru dot is
                   ` (2 preceding siblings ...)
  2003-10-08 13:08 ` paolo at gcc dot gnu dot org
@ 2003-10-16 17:24 ` cvs-commit at gcc dot gnu dot org
  2003-10-16 17:59 ` paolo at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2003-10-16 17:24 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12540



------- Additional Comments From cvs-commit at gcc dot gnu dot org  2003-10-16 17:24 -------
Subject: Bug 12540

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	paolo@gcc.gnu.org	2003-10-16 17:24:07

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/src: locale.cc 
	libstdc++-v3/config/locale/gnu: monetary_members.cc 

Log message:
	2003-10-16  Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/12540
	* config/locale/gnu/monetary_members.cc
	(moneypunct<wchar_t, true/false>::_M_initialize_moneypunct):
	Don't leak memory if new throws.
	* src/locale.cc (locale::locale(const char*)): In order not
	to leak memory in case new throws, use a basic_string type
	for __res too and avoid strdup.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&r1=1.2015&r2=1.2016
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/src/locale.cc.diff?cvsroot=gcc&r1=1.97&r2=1.98
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/config/locale/gnu/monetary_members.cc.diff?cvsroot=gcc&r1=1.11&r2=1.12


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/12540] Memory leak in locale::locale(const char*)
  2003-10-08 12:22 [Bug libstdc++/12540] New: Memory leak in locale::locale(const char*) peturr02 at ru dot is
                   ` (3 preceding siblings ...)
  2003-10-16 17:24 ` cvs-commit at gcc dot gnu dot org
@ 2003-10-16 17:59 ` paolo at gcc dot gnu dot org
  2003-10-17 18:20 ` pinskia at gcc dot gnu dot org
  2004-01-29  2:35 ` pcarlini at suse dot de
  6 siblings, 0 replies; 8+ messages in thread
From: paolo at gcc dot gnu dot org @ 2003-10-16 17:59 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12540


paolo at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


------- Additional Comments From paolo at gcc dot gnu dot org  2003-10-16 17:59 -------
Fixed for 3.4.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/12540] Memory leak in locale::locale(const char*)
  2003-10-08 12:22 [Bug libstdc++/12540] New: Memory leak in locale::locale(const char*) peturr02 at ru dot is
                   ` (4 preceding siblings ...)
  2003-10-16 17:59 ` paolo at gcc dot gnu dot org
@ 2003-10-17 18:20 ` pinskia at gcc dot gnu dot org
  2004-01-29  2:35 ` pcarlini at suse dot de
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-10-17 18:20 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12540


pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |3.4


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/12540] Memory leak in locale::locale(const char*)
  2003-10-08 12:22 [Bug libstdc++/12540] New: Memory leak in locale::locale(const char*) peturr02 at ru dot is
                   ` (5 preceding siblings ...)
  2003-10-17 18:20 ` pinskia at gcc dot gnu dot org
@ 2004-01-29  2:35 ` pcarlini at suse dot de
  6 siblings, 0 replies; 8+ messages in thread
From: pcarlini at suse dot de @ 2004-01-29  2:35 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|3.4.0                       |3.3.3


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12540


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-01-29  2:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-08 12:22 [Bug libstdc++/12540] New: Memory leak in locale::locale(const char*) peturr02 at ru dot is
2003-10-08 12:25 ` [Bug libstdc++/12540] " peturr02 at ru dot is
2003-10-08 12:26 ` peturr02 at ru dot is
2003-10-08 13:08 ` paolo at gcc dot gnu dot org
2003-10-16 17:24 ` cvs-commit at gcc dot gnu dot org
2003-10-16 17:59 ` paolo at gcc dot gnu dot org
2003-10-17 18:20 ` pinskia at gcc dot gnu dot org
2004-01-29  2:35 ` pcarlini at suse dot de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).