From 340dd95c6a566b01bfaf9ce2baa0b49f07e3ac22 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 8 Oct 2023 12:02:58 -0700 Subject: XkbChangeAtomDisplay: stop leaking atom name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found by gcc 12 analyzer: xkbatom.c: In function ‘XkbChangeAtomDisplay’: xkbatom.c:218:16: warning: leak of ‘tmp’ [CWE-401] [-Wanalyzer-malloc-leak] xkbatom.c:220:12: warning: leak of ‘tmp’ [CWE-401] [-Wanalyzer-malloc-leak] 220 | return XInternAtom(dpy, name, onlyIfExists); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Fixes: 5e5bd09 ("Fix offline operation.") Signed-off-by: Alan Coopersmith --- src/xkbatom.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/xkbatom.c b/src/xkbatom.c index b6feac6..3a7e08b 100644 --- a/src/xkbatom.c +++ b/src/xkbatom.c @@ -225,12 +225,13 @@ XkbInternAtom(Display *dpy, const char *name, Bool onlyIfExists) Atom XkbChangeAtomDisplay(Display *oldDpy, Display *newDpy, Atom atm) { - char *tmp; - if (atm != None) { - tmp = XkbAtomGetString(oldDpy, atm); - if (tmp != NULL) - return XkbInternAtom(newDpy, tmp, False); + char *tmp = XkbAtomGetString(oldDpy, atm); + if (tmp != NULL) { + Atom a = XkbInternAtom(newDpy, tmp, False); + _XkbFree(tmp); + return a; + } } return None; } -- cgit v1.2.3