From b72a2f0e8a79b37422dc63a5a74a5c7b69c0d333 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 4 Apr 2026 15:01:48 -0700 Subject: [PATCH] xkb: plug memory leaks in InitKeyboardDeviceStructInternal() error paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Part-of: (cherry picked from commit 97cf051dfc5770d7b08701c923581e7e53569cd6) --- xkb/xkbInit.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xkb/xkbInit.c b/xkb/xkbInit.c index 4108e1b26..0178d4da3 100644 --- a/xkb/xkbInit.c +++ b/xkb/xkbInit.c @@ -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; }