From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30061 invoked by alias); 8 Oct 2003 12:22:08 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 30052 invoked by uid 48); 8 Oct 2003 12:22:07 -0000 Date: Wed, 08 Oct 2003 12:22:00 -0000 From: "peturr02 at ru dot is" To: gcc-bugs@gcc.gnu.org Message-ID: <20031008122204.12540.peturr02@ru.is> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug libstdc++/12540] New: Memory leak in locale::locale(const char*) X-Bugzilla-Reason: CC X-SW-Source: 2003-10/txt/msg00525.txt.bz2 List-Id: 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.