<html>
<head>
<base href="https://bugzilla.gnome.org/" />
</head>
<body>
<p>
<div>
<b><a class="bz_bug_link
bz_status_NEW "
title="NEW - gdk_keymap_get_entries_for_keyval() returns TRUE with n_keys=0 in Wayland"
href="https://bugzilla.gnome.org/show_bug.cgi?id=787069#c3">Comment # 3</a>
on <a class="bz_bug_link
bz_status_NEW "
title="NEW - gdk_keymap_get_entries_for_keyval() returns TRUE with n_keys=0 in Wayland"
href="https://bugzilla.gnome.org/show_bug.cgi?id=787069">bug 787069</a>
from <span class="vcard"><a href="page.cgi?id=describeuser.html&login=carlosgc%40gnome.org" title="Carlos Garcia Campos <carlosgc@gnome.org>"> <span class="fn">Carlos Garcia Campos</span></a>
</span></b>
<pre>(In reply to Christian Persch from <a href="show_bug.cgi?id=787069#c2">comment #2</a>)
<span class="quote">> Existing code using this may do
>
> if (gdk_keymap_get_entries_for_keyval(..., &keys, &n_keys)) {
> /* do something */
> g_free(keys);
> }
>
> (e.g. firefox does this).
>
> The patch returns FALSE on n_keys == 0, but still keys != NULL, which means
> a leak on the code pattern above. Should also change to set return keys =
> NULL in this case, I think.</span >
I'm not sure that can happen, at least in the mir and wayland implementations,
if n_keys == 0, then they GArray was created but never changed, so the internal
pointer is still NULL. The GArray itself is freed, so I don't think there's any
leak. We could still do the same X11 backend does to be extra sure:
if (retval->len > 0)
{
*keys = (GdkKeymapKey*) retval->data;
*n_keys = retval->len;
}
else
{
*keys = NULL;
*n_keys = 0;
}
g_array_free (retval, retval->len > 0 ? FALSE : TRUE);
return *n_keys > 0;</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>