From nobody Sat May 18 05:53:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1619797815; cv=none; d=zohomail.com; s=zohoarc; b=GBHhZTshKSrubV0C1FZLQylN4xCTjsXa/L8MGysWejB5e1Tc2slSEAY36L+GvUy/EExXtYVMWTeQ2xe5Ah4uuCEUJ0YOplf+WHHoLIvF0T9CPHnqjd4/P3F5Iqlj8NPfHGvRb10nhbdmn/ud23HdHyqEPnNqdyucE5Fg8e4s+E0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619797815; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=rePuRUmiJLdH/917Gz9nV9f0upTX5GXwfFmefbXYyi0=; b=EnbPYQv3Zxi9pKRlwjA8v7ssF7IukJcvdHyL+GBPEykLCMXh7LR3Raqpl+UZU2BLAsCnN4aGZ3kPYd9w13mFZUUTmu3ZfklLNmuzMTUzJ+jI7B0Ef2FpjixmqwvHx3XhIGb+LdGS3l5m3aIrMx5sbmARwTRadwO9nwfidNdKAw4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1619797815774497.4292588383837; Fri, 30 Apr 2021 08:50:15 -0700 (PDT) Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-213--lP4lQ_tPAK4CqnABGOM3A-1; Fri, 30 Apr 2021 11:50:12 -0400 Received: by mail-wr1-f72.google.com with SMTP id i32-20020adf90a30000b029010d9e6b3833so1469584wri.18 for ; Fri, 30 Apr 2021 08:50:12 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (anancy-651-1-208-144.w109-217.abo.wanadoo.fr. [109.217.237.144]) by smtp.gmail.com with ESMTPSA id d13sm2734708wrx.29.2021.04.30.08.50.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 08:50:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619797814; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rePuRUmiJLdH/917Gz9nV9f0upTX5GXwfFmefbXYyi0=; b=bGfUaHaqe7EtOr4Hi6UsnWS1yHlX7hfaRMuSooV7M2fksf27Q1uOR1splGG0QC6FoKCwIi BEhIGYN8BQ+j3RGeXej+myn7hSB3TaTkiqbuh5GdooxgZ+uhpTpMTS9WsUGD69w9dRwvJU It4TkgdQ+I0g+N3Y5ACPs2nWjKHZkho= X-MC-Unique: -lP4lQ_tPAK4CqnABGOM3A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rePuRUmiJLdH/917Gz9nV9f0upTX5GXwfFmefbXYyi0=; b=OyFpAjMWvttdAVFmauxQd4E+yRJ7SfRy6enimmjPW9XYbf+EdyPfVXgK4f+MUWRW1+ fYmlbyPue9qtPH/6FbdT7Ej3QseIuaWScjrrU/FXhSFfGdQqPSHG+t7XhFHJWnZriJTi A1B8Czko+ql9hCROmoGiBxYznzblUSJAY8Iv1ooRvTUQJd6DWdJmAqnOX/fII1gMaTt8 ZijzkBBjw+emfJqBmG9hKh2lpjuLuG50h48VyFq2mlqZALDSIi8waV+1K8hKP1UN97y7 shr4SAO7CHSlFSRN71bJ/dYlCjXlwGlNpzGqy6QbhVdOF4nGmmmWKM2esoxJmXa6eQHz zUmA== X-Gm-Message-State: AOAM533zvJNkY7jmnIKOyPjPJt7tz79aXwUsLFwam5vIvKe/I7P4Ke5L 41ewCLKxXas92UONG2T/j+l0hiAjdZvMRfJAgc5iSPgulBXIzdBV+bVpWN+ghikq6y81N4qrljY C2w+jBVFu4AGBBg== X-Received: by 2002:a5d:648e:: with SMTP id o14mr4567324wri.27.1619797811545; Fri, 30 Apr 2021 08:50:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyffMx0y3ZAkVjuP/N2GjT+l6HIG1+RM1o58430MeT8aaNw2e6UYVpEyBNS772g5Uo8a3kqpA== X-Received: by 2002:a5d:648e:: with SMTP id o14mr4567316wri.27.1619797811433; Fri, 30 Apr 2021 08:50:11 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , qemu-trivial@nongnu.org, "Daniel P . Berrange" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2] ui: Fix memory leak in qemu_xkeymap_mapping_table() Date: Fri, 30 Apr 2021 17:50:09 +0200 Message-Id: <20210430155009.259755-1-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @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=C3=A9 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Laurent Vivier --- 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 555086fb6bd..2ce7b899615 100644 --- a/ui/x_keymap.c +++ b/ui/x_keymap.c @@ -56,6 +56,7 @@ const guint16 *qemu_xkeymap_mapping_table(Display *dpy, s= ize_t *maplen) { XkbDescPtr desc; const gchar *keycodes =3D NULL; + const guint16 *map; =20 /* 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 =3D qemu_input_map_xorgxwin_to_qcode_len; - return qemu_input_map_xorgxwin_to_qcode; + map =3D qemu_input_map_xorgxwin_to_qcode; } else if (check_for_xquartz(dpy)) { trace_xkeymap_keymap("xquartz"); *maplen =3D qemu_input_map_xorgxquartz_to_qcode_len; - return qemu_input_map_xorgxquartz_to_qcode; + map =3D qemu_input_map_xorgxquartz_to_qcode; } else if ((keycodes && g_str_has_prefix(keycodes, "evdev")) || (XKeysymToKeycode(dpy, XK_Page_Up) =3D=3D 0x70)) { trace_xkeymap_keymap("evdev"); *maplen =3D qemu_input_map_xorgevdev_to_qcode_len; - return qemu_input_map_xorgevdev_to_qcode; + map =3D qemu_input_map_xorgevdev_to_qcode; } else if ((keycodes && g_str_has_prefix(keycodes, "xfree86")) || (XKeysymToKeycode(dpy, XK_Page_Up) =3D=3D 0x63)) { trace_xkeymap_keymap("kbd"); *maplen =3D qemu_input_map_xorgkbd_to_qcode_len; - return qemu_input_map_xorgkbd_to_qcode; + map =3D 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 : ""); - return NULL; + map =3D NULL; } + if (keycodes) { + XFree((void *)keycodes); + } + return map; } --=20 2.26.3