[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-bindings
Subject:    Re: [Kde-bindings] QtRuby memleak continued
From:       Richard Dale <rdale () foton ! es>
Date:       2006-09-01 10:54:54
Message-ID: 200609011154.55066.rdale () foton ! es
[Download RAW message or body]

On Friday 01 September 2006 08:32, Ashley Winters wrote:
> --- Ashley Winters <jahqueel@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. :)
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
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic