[Kde-bindings] QtRuby memleak continued
Ashley Winters
jahqueel at yahoo.com
Fri Sep 1 07:32:07 UTC 2006
--- Ashley Winters <jahqueel at yahoo.com> wrote:
> In the latest Qt4 version, the m->cleanup() logic has been commented
> out. Is there a reason?
Found it. I was looking in the wrong spot. Here's one leak that I think
I see:
template <>
static char* ruby_to_primitive<char *>(VALUE v)
{
if(v == Qnil)
return 0;
// hello strdup() leak
return strdup(StringValuePtr(v));
}
template <>
static void marshall_from_ruby<char *>(Marshall *m)
{
VALUE obj = *(m->var());
// new pointer assigned, and then lost?
m->item().s_voidp = ruby_to_primitive<char*>(obj);
}
The proper fix would be to remove the strdup() from
ruby_to_primitive<char *>:
- return strdup(StringValuePtr(v));
+ return StringValuePtr(v);
and move it to the marshall_from_ruby<char *> function:
- m->item().s_voidp = ruby_to_primitive<char*>(obj);
+ char *s = ruby_to_primitive<char*>(obj);
+ m->item().s_voidp = m->cleanup() ? strdup(s) : s;
At least, I'd guess it was the fix. Not that I've tested it, or
anything. :)
- Ashley Winters
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Kde-bindings
mailing list