[Wayland-bugs] [Bug 787069] gdk_keymap_get_entries_for_keyval() returns TRUE with n_keys=0 in Wayland
gtk+ (GNOME Bugzilla)
bugzilla at gnome.org
Fri Sep 1 06:45:11 UTC 2017
https://bugzilla.gnome.org/show_bug.cgi?id=787069
--- Comment #3 from Carlos Garcia Campos <carlosgc at gnome.org> ---
(In reply to Christian Persch from comment #2)
> 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.
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;
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/wayland-bugs/attachments/20170901/897c18e7/attachment-0001.html>
More information about the wayland-bugs
mailing list