From kde-bindings Fri Sep 01 10:54:54 2006 From: Richard Dale Date: Fri, 01 Sep 2006 10:54:54 +0000 To: kde-bindings Subject: Re: [Kde-bindings] QtRuby memleak continued Message-Id: <200609011154.55066.rdale () foton ! es> X-MARC-Message: https://marc.info/?l=kde-bindings&m=115710813827064 On Friday 01 September 2006 08:32, Ashley Winters wrote: > --- Ashley Winters 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(VALUE v) > { > if(v == Qnil) > return 0; > > // hello strdup() leak > return strdup(StringValuePtr(v)); > } > > template <> > static void marshall_from_ruby(Marshall *m) > { > VALUE obj = *(m->var()); > > // new pointer assigned, and then lost? > m->item().s_voidp = ruby_to_primitive(obj); > } > > The proper fix would be to remove the strdup() from > ruby_to_primitive: > > - return strdup(StringValuePtr(v)); > + return StringValuePtr(v); > > and move it to the marshall_from_ruby function: > > - m->item().s_voidp = ruby_to_primitive(obj); > + char *s = ruby_to_primitive(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. :) I added the strdup() to fix a bug in KAboutData: KAboutData( const char *appName, const char *programName, const char *version, const char *shortDescription = 0, int licenseType = License_Unknown, const char *copyrightStatement = 0, const char *text = 0, const char *homePageAddress = 0, const char *bugsEmailAddress = "submit@bugs.kde.org" ); QtRuby was deleting the 'char *'s after they were passed to the call, but that meant they were junk in the app's Help->About menu. So perhaps it was the wrong way to fix it, but how can you tell whether or not you are supposed to free the 'char *' after the call? In Ruby the C api always takes a copy of the 'char *' and so it would be correct to delete it. I've no idea why these args aren't QStrings anyway, it all seems pretty ugly and won't handle unicode in people's names. -- Richard _______________________________________________ Kde-bindings mailing list Kde-bindings@kde.org https://mail.kde.org/mailman/listinfo/kde-bindings