This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Serious memory leak in C++ string when compiling with -fPIC


Consider the following program:

leaklib.cc
----------
#include <string>

string get_string () {
    return "blah";
}

leaktest.cc
-----------
#include <string>

string get_string ();

void leak () {
    string tmp = get_string();
}

int main () {
    while (true)
        leak();

    return 0;
}

If I compile this like this:
g++ -c leaklib.cc
g++ -o leaktest leaktest.cc leaklib.o

the leaktest program does not leak. But if I add the -fPIC option
(necessary if this was a real shared library):
g++ -fPIC -c leaklib.cc
g++ -o leaktest leaktest.cc leaklib.o

the leaktest program leaks about 18M per second. It seems we can't call
a function in a shared library that returns a C++ string! This is a big
problem for our project (we are using the Gtk-- library).

This is with egcs 1.1.1, binutils 2.9.1.0.19a,
libstdc++-2-libc6.0-1-2.9.0 on a Debian 2.1 system. bastring.cc is dated
July 11, 1998, if that helps.

We can workaround the problem by compiling statically, but would really
like a better solution. Thanks.

--
Michael Babcock
Jim Henson's Creature Shop - Los Angeles
mbabcock@la.creatureshop.henson.com



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]