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

List:       kde-bindings
Subject:    Re: [Kde-bindings] QtRuby memleak continued
From:       Ashley Winters <jahqueel () yahoo ! com>
Date:       2006-09-01 7:32:07
Message-ID: 20060901073207.88927.qmail () web50904 ! mail ! yahoo ! com
[Download RAW message or body]

--- 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. :)

- Ashley Winters


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
_______________________________________________
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