[Kde-bindings] [Bug 108650] memory leak in qtruby? (Qt::Socket)
Richard Dale
Richard_Dale at tipitina.demon.co.uk
Fri Jul 8 12:45:53 UTC 2005
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
http://bugs.kde.org/show_bug.cgi?id=108650
------- Additional Comments From Richard_Dale tipitina demon co uk 2005-07-08 14:45 -------
On Wednesday 06 July 2005 14:42, Caleb Tennis wrote:
[bugs.kde.org quoted mail]
Yes, you're right there is a leak for QString value return types. When a Smoke
method returns a QString, it creates a new temporary QString with 'new', but
never deletes it. I also tried 'QString*' and 'QString&' return types with
readLine(), and those don't create a temporary string.
virtual QString readLine();
Generates this code:
void x_45(Smoke::Stack x) {
// readLine()
QString xret = this->QSocket::readLine();
x[0].s_voidp = (void*)new QString(xret);
}
virtual QString * readLine(); Becomes
Generates this code:
void x_45(Smoke::Stack x) {
// readLine()
QString* xret = this->QSocket::readLine();
x[0].s_voidp = (void*)xret;
}
virtual QString & readLine();
Generates this code:
void x_45(Smoke::Stack x) {
// readLine()
QString& xret = this->QSocket::readLine();
x[0].s_voidp = (void*)&xret;
}
In Qt.cpp, the class to handle a return value has a boolean method called
cleanup(), which is false.
class MethodReturnValue : public Marshall {
...
bool cleanup() { return false; }
};
In handlers.cpp, the code to marshall a QString to a ruby string will only
delete the QString if cleanup() is true:
case Marshall::ToVALUE:
{
QString *s = (QString*)m->item().s_voidp;
if(s) {
if (s->isNull()) {
*(m->var()) = Qnil;
} else {
*(m->var()) = rstringFromQString(s);
}
if(m->cleanup())
delete s;
} else {
*(m->var()) = Qnil;
}
}
So the temporary QString from the 'QString readLine()' version of the method
is never deleted. Either cleanup() should return true in MethodReturnValue,
or the marshalling code should check if the QString is a value type and only
delete it if it is.
I looked at the PerlQt code in PerlQt-3.009 beta and it's just the same, and
will have this leak too.
-- Richard
More information about the Kde-bindings
mailing list