This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Leakage from initialization of pair<..., string>
- From: Wu Yongwei <adah at sh163 dot net>
- To: gcc at gcc dot gnu dot org
- Date: 03 Jul 2004 23:05:08 +0800
- Subject: Leakage from initialization of pair<..., string>
Tracing the memory allocation/deallocation of the following short
program shows a problem:
------------------------------------------------------------
#include <memory>
#include <string>
typedef std::pair<unsigned, std::string> uint_str_t;
std::pair<unsigned, std::string> g_key_id_name_pairs[] = {
uint_str_t(64, "@"),
uint_str_t(65, "A"),
uint_str_t(66, "B")
};
int main()
{
}
------------------------------------------------------------
Three times operator new(14) are called, with no operator delete called
(when GLIBCPP_FORCE_NEW=1). This problem is confirmed to exist on (at
least) MinGW GCC 3.3.1, MinGW GCC 3.4, and Linux GCC 3.2.3. This problem
does not exist on GCC 2.95.3.
Using real struct in place of pair will not cause the leak. Using a
simplistic user-defined string implementation will not, either. I am
guessing it is from some specific implementation of string (maybe
reference counting?). I did not trace it out (as an end user I am unable
to trace into string; I have not much experience in building gcc
myself).
Anyone with clues?
Best regards,
WU Yongwei