xkb: plug memory leaks in InitKeyboardDeviceStructInternal() error paths

Reported in #1817:
xwayland-24.1.6/redhat-linux-build/../xkb/xkbInit.c:527:5:
  warning[-Wanalyzer-malloc-leak]: leak of ‘rmlvo_dflts.layout’
xwayland-24.1.6/redhat-linux-build/../xkb/xkbInit.c:527:5:
  warning[-Wanalyzer-malloc-leak]: leak of ‘rmlvo_dflts.model’
xwayland-24.1.6/redhat-linux-build/../xkb/xkbInit.c:527:5:
  warning[-Wanalyzer-malloc-leak]: leak of ‘rmlvo_dflts.options’
xwayland-24.1.6/redhat-linux-build/../xkb/xkbInit.c:527:5:
  warning[-Wanalyzer-malloc-leak]: leak of ‘rmlvo_dflts.rules’
xwayland-24.1.6/redhat-linux-build/../xkb/xkbInit.c:527:5:
  warning[-Wanalyzer-malloc-leak]: leak of ‘rmlvo_dflts.variant’

Fixes: 56a5955c8 ("xkb: strdup the values returned by XkbGetRulesDflts")
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2169>
(cherry picked from commit 97cf051dfc)
This commit is contained in:
Alan Coopersmith 2026-04-04 15:01:48 -07:00 committed by Peter Hutterer
parent ed4a6bdff6
commit b72a2f0e8a

View file

@ -542,7 +542,7 @@ InitKeyboardDeviceStructInternal(DeviceIntPtr dev, XkbRMLVOSet * rmlvo,
dev->key = calloc(1, sizeof(*dev->key));
if (!dev->key) {
ErrorF("XKB: Failed to allocate key class\n");
return FALSE;
goto unwind_rmlvo;
}
dev->key->sourceid = dev->id;
@ -661,6 +661,8 @@ InitKeyboardDeviceStructInternal(DeviceIntPtr dev, XkbRMLVOSet * rmlvo,
unwind_key:
free(dev->key);
dev->key = NULL;
unwind_rmlvo:
XkbFreeRMLVOSet(&rmlvo_dflts, FALSE);
return FALSE;
}