summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-10-08 12:02:58 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-10-08 12:07:02 -0700
commit340dd95c6a566b01bfaf9ce2baa0b49f07e3ac22 (patch)
treefa1420899e51f1045338a313c90cdd7ec7eed4ce
parenta8c782571d3b2419404f3a623f4b5396cd5e7aa4 (diff)
XkbChangeAtomDisplay: stop leaking atom name
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 <alan.coopersmith@oracle.com>
-rw-r--r--src/xkbatom.c11
1 files 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;
}