was: [gtkmm] Memory leak in Gtk_Entry::get_text() (fwd)

I found this on the gtk-- mailing list.

---------- Forwarded message ----------
Date: Tue, 18 May 1999 14:48:54 -0700
Subject: [gtkmm] Memory leak in Gtk_Entry::get_text()

I was having a big problem with a memory leak that I tracked down to the
Gtk_Entry::get_text function. After further investigation it seems that
Gtk-- is not at fault, but I thought I'd copy this message I sent to the
egcs-bugs list in case other people are having the same problem.

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.

--

Reply via email to