Memory leak in XkbGetMap and a portability question

Shachar Shemesh shachar at
Sat Mar 24 23:19:51 PDT 2007

More precisely, in XkbFreeClientMap, I think.

Hi all,

I'm trying to get my mind wrapped around using XKB for getting the
current keyboard language. First, a proper link to the Xkb documentation
(wikipedia finally proved helpful, but it was far from being the first
place I'd look) would have been better.

I found two approaches for doing what I wanted to do. The first was to
use XkbGetMap followed by XkbGetNames. The second was to use
XkbRF_GetNamesProp. The later's major advantage is that it gives me easy
to parse results. I need to automatically detect what language a given
XKB group is, and XkbRF_GetNamesProp is much easier to parse in cases
where variants exist.

XkbRF_GetNamesProp's greatest disadvantage is that it seems totally
undocumented. After asking around, I was also told that it is not wire
compatible with just any X server, which makes it quite unusable for my

The first thing I would like is a confirmation that XkbGetNames is the
best API for getting the languages for the different groups.

I wrote a small program that connects to the X server, enables the Xkb
extension, uses XkbGetMap and XkbGetNames in order to retrieve that
names of the groups, as well as XkbGetState, and then frees everything
up using:
    XkbFreeNames(xkbDesc, XkbAllNamesMask, True);
    XkbFreeClientMap(xkbDesc, XkbAllMapComponentsMask, True);

If I use XkbGetMap with a mask of 0, valgrind reports 40 bytes of memory
lost in unreachable code, and 22 bytes in reachable code. No matter how
many times I close and open the display, the 22 bytes part remains more
or less constant, so I'm going to write that down as overhead and ignore
it. It doesn't threaten the stability of my program.

The 40 bytes, however, are a more serious problem. For every call to
XkbGetMap I perform in my program I lose 40 bytes. If I use a less empty
mask for the information to retrieve I lose more bytes per call. It
seems to me that either XkbFreeClientMap is not doing its job properly
or the docs failed to mention another freeing function that needs to be

I'll just mention that calling XkbGetUpdatedMap does not further leak
memory, so I do have a solution to my immediate need of the library.
Still, I think it could be constructive to make sure we deallocate
everything we allocated.


More information about the xorg mailing list