Leak in XKeysymToString

Keith Packard keithp at keithp.com
Mon Aug 22 18:07:33 UTC 2022


Thomas Dickey <dickey at his.com> writes:

> The manpage hints that callers should make a copy of the string,
> since that "static area" implies that the library overwrites the
> data for each call:
>
>        The returned string is in a static area and must not be modified.  The
>        returned string is in the Host Portable Character Encoding.  If the
>        specified KeySym is not defined, XKeysymToString returns a NULL.

Yeah, I don't think that's really a hint that the caller should make a
copy though -- for all "classic" keysyms, you're getting a pointer into
_XkeyTable, which you wouldn't need to copy to preserve.

How about something super simple -- just stick the string in the Xrm
quark table and return that?

        char s[10];
        ...
        return XrmQuarkToString(XrmStringToQuark(s))

The current implementation, leaky as it is, seems like a "safe"
alternative until someone wants to spend time fixing it in a way which
preserves the values of returned strings 'forever', as is the case with
all other return values.

-- 
-keith
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <https://lists.x.org/archives/xorg-devel/attachments/20220822/1ec59cf7/attachment.sig>


More information about the xorg-devel mailing list