From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Daniel P . Berrangé" <berrange@redhat.com>,
"Michael Tokarev" <mjt@tls.msk.ru>,
"Laurent Vivier" <laurent@vivier.eu>
Subject: [PULL 10/23] ui: Fix memory leak in qemu_xkeymap_mapping_table()
Date: Mon, 3 May 2021 10:36:10 +0200 [thread overview]
Message-ID: <20210503083623.139700-11-laurent@vivier.eu> (raw)
In-Reply-To: <20210503083623.139700-1-laurent@vivier.eu>
From: Philippe Mathieu-Daudé <philmd@redhat.com>
Refactor qemu_xkeymap_mapping_table() to have a single exit point,
so we can easily free the memory allocated by XGetAtomName().
This fixes when running a binary configured with --enable-sanitizers:
Direct leak of 22 byte(s) in 1 object(s) allocated from:
#0 0x561344a7473f in malloc (qemu-system-x86_64+0x1dab73f)
#1 0x7fa4d9dc08aa in XGetAtomName (/lib64/libX11.so.6+0x2a8aa)
Fixes: 2ec78706d18 ("ui: convert GTK and SDL1 frontends to keycodemapdb")
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20210430155009.259755-1-philmd@redhat.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
ui/x_keymap.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/ui/x_keymap.c b/ui/x_keymap.c
index 555086fb6bd5..2ce7b899615f 100644
--- a/ui/x_keymap.c
+++ b/ui/x_keymap.c
@@ -56,6 +56,7 @@ const guint16 *qemu_xkeymap_mapping_table(Display *dpy, size_t *maplen)
{
XkbDescPtr desc;
const gchar *keycodes = NULL;
+ const guint16 *map;
/* There is no easy way to determine what X11 server
* and platform & keyboard driver is in use. Thus we
@@ -83,21 +84,21 @@ const guint16 *qemu_xkeymap_mapping_table(Display *dpy, size_t *maplen)
if (check_for_xwin(dpy)) {
trace_xkeymap_keymap("xwin");
*maplen = qemu_input_map_xorgxwin_to_qcode_len;
- return qemu_input_map_xorgxwin_to_qcode;
+ map = qemu_input_map_xorgxwin_to_qcode;
} else if (check_for_xquartz(dpy)) {
trace_xkeymap_keymap("xquartz");
*maplen = qemu_input_map_xorgxquartz_to_qcode_len;
- return qemu_input_map_xorgxquartz_to_qcode;
+ map = qemu_input_map_xorgxquartz_to_qcode;
} else if ((keycodes && g_str_has_prefix(keycodes, "evdev")) ||
(XKeysymToKeycode(dpy, XK_Page_Up) == 0x70)) {
trace_xkeymap_keymap("evdev");
*maplen = qemu_input_map_xorgevdev_to_qcode_len;
- return qemu_input_map_xorgevdev_to_qcode;
+ map = qemu_input_map_xorgevdev_to_qcode;
} else if ((keycodes && g_str_has_prefix(keycodes, "xfree86")) ||
(XKeysymToKeycode(dpy, XK_Page_Up) == 0x63)) {
trace_xkeymap_keymap("kbd");
*maplen = qemu_input_map_xorgkbd_to_qcode_len;
- return qemu_input_map_xorgkbd_to_qcode;
+ map = qemu_input_map_xorgkbd_to_qcode;
} else {
trace_xkeymap_keymap("NULL");
g_warning("Unknown X11 keycode mapping '%s'.\n"
@@ -109,6 +110,10 @@ const guint16 *qemu_xkeymap_mapping_table(Display *dpy, size_t *maplen)
" - xprop -root\n"
" - xdpyinfo\n",
keycodes ? keycodes : "<null>");
- return NULL;
+ map = NULL;
}
+ if (keycodes) {
+ XFree((void *)keycodes);
+ }
+ return map;
}
--
2.31.1
next prev parent reply other threads:[~2021-05-03 8:40 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-03 8:36 [PULL 00/23] Trivial branch for 6.1 patches Laurent Vivier
2021-05-03 8:36 ` [PULL 01/23] accel: kvm: clarify that extra exit data is hexadecimal Laurent Vivier
2021-05-03 8:36 ` [PULL 02/23] hw/arm/pxa2xx: Declare PCMCIA bus with Kconfig Laurent Vivier
2021-05-03 8:36 ` [PULL 03/23] hw/ide: Add Kconfig dependency MICRODRIVE -> PCMCIA Laurent Vivier
2021-05-03 8:36 ` [PULL 04/23] hw/pcmcia: Do not register PCMCIA type if not required Laurent Vivier
2021-05-03 8:36 ` [PULL 05/23] Fix typo in CFI build documentation Laurent Vivier
2021-05-03 8:36 ` [PULL 06/23] vmstate: Constify some VMStateDescriptions Laurent Vivier
2021-05-03 8:36 ` [PULL 07/23] hw/arm: Constify VMStateDescription Laurent Vivier
2021-05-03 8:36 ` [PULL 08/23] hw/display/qxl: " Laurent Vivier
2021-05-03 8:36 ` [PULL 09/23] hw/usb: " Laurent Vivier
2021-05-03 8:36 ` Laurent Vivier [this message]
2021-05-03 8:36 ` [PULL 11/23] hw: Remove superfluous includes of hw/hw.h Laurent Vivier
2021-05-03 8:36 ` [PULL 12/23] hw: Do not include hw/sysbus.h if it is not necessary Laurent Vivier
2021-05-03 8:36 ` [PULL 13/23] hw: Do not include hw/irq.h " Laurent Vivier
2021-05-03 8:36 ` [PULL 14/23] hw: Do not include qemu/log.h " Laurent Vivier
2021-05-03 8:36 ` [PULL 15/23] Do not include sysemu/sysemu.h if it's not really necessary Laurent Vivier
2021-05-03 8:36 ` [PULL 16/23] Do not include hw/boards.h " Laurent Vivier
2021-05-03 8:36 ` [PULL 17/23] Do not include cpu.h " Laurent Vivier
2021-05-03 8:36 ` [PULL 18/23] Do not include exec/address-spaces.h " Laurent Vivier
2021-05-03 8:36 ` [PULL 19/23] mc146818rtc: put it into the 'misc' category Laurent Vivier
2021-05-03 8:36 ` [PULL 20/23] docs/system: Document the removal of "compat" property for POWER CPUs Laurent Vivier
2021-05-03 8:36 ` [PULL 21/23] scripts: fix generation update-binfmts templates Laurent Vivier
2021-05-03 8:36 ` [PULL 22/23] docs: More precisely describe memory-backend-*::id's user Laurent Vivier
2021-05-03 8:36 ` [PULL 23/23] hw/rx/rx-gdbsim: Do not accept invalid memory size Laurent Vivier
2021-05-05 17:37 ` [PULL 00/23] Trivial branch for 6.1 patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210503083623.139700-11-laurent@vivier.eu \
--to=laurent@vivier.eu \
--cc=berrange@redhat.com \
--cc=mjt@tls.msk.ru \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).