From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MKSpC-0008DC-Nz for qemu-devel@nongnu.org; Sat, 27 Jun 2009 03:59:50 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MKSp8-0008AX-Nm for qemu-devel@nongnu.org; Sat, 27 Jun 2009 03:59:50 -0400 Received: from [199.232.76.173] (port=52119 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MKSp8-0008AM-Ht for qemu-devel@nongnu.org; Sat, 27 Jun 2009 03:59:46 -0400 Received: from fmmailgate01.web.de ([217.72.192.221]:45657) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MKSp7-0007mK-U0 for qemu-devel@nongnu.org; Sat, 27 Jun 2009 03:59:46 -0400 Message-ID: <4A45D16C.5040703@web.de> Date: Sat, 27 Jun 2009 09:59:40 +0200 From: Jan Kiszka MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigF35DAD1B6966B742823D53F5" Sender: jan.kiszka@web.de Subject: [Qemu-devel] [RESEND][PATCH] sdl: Fix memory leakage List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: qemu-devel This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigF35DAD1B6966B742823D53F5 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Valgrind was so kind to remark that no one bothers to release keycodes after use and that something is fishy about cleaning up the requested keyboard descriptor. With this patch applied, we no longer leak about 12k during startup. Signed-off-by: Jan Kiszka --- sdl.c | 39 +++++++++++++++++++++------------------ 1 files changed, 21 insertions(+), 18 deletions(-) diff --git a/sdl.c b/sdl.c index 178b553..35e12f6 100644 --- a/sdl.c +++ b/sdl.c @@ -234,32 +234,35 @@ static uint8_t sdl_keyevent_to_keycode(const SDL_Ke= yboardEvent *ev) static int check_for_evdev(void) { SDL_SysWMinfo info; - XkbDescPtr desc; + XkbDescPtr desc =3D NULL; int has_evdev =3D 0; - const char *keycodes; + char *keycodes =3D NULL; =20 SDL_VERSION(&info.version); - if (!SDL_GetWMInfo(&info)) + if (!SDL_GetWMInfo(&info)) { return 0; - + } desc =3D XkbGetKeyboard(info.info.x11.display, XkbGBN_AllComponentsMask, XkbUseCoreKbd); - if (desc =3D=3D NULL || desc->names =3D=3D NULL) - return 0; - - keycodes =3D XGetAtomName(info.info.x11.display, desc->names->keycod= es); - if (keycodes =3D=3D NULL) - fprintf(stderr, "could not lookup keycode name\n"); - else if (strstart(keycodes, "evdev", NULL)) - has_evdev =3D 1; - else if (!strstart(keycodes, "xfree86", NULL)) - fprintf(stderr, - "unknown keycodes `%s', please report to qemu-devel@nong= nu.org\n", - keycodes); - - XkbFreeClientMap(desc, XkbGBN_AllComponentsMask, True); + if (desc && desc->names) { + keycodes =3D XGetAtomName(info.info.x11.display, desc->names->ke= ycodes); + if (keycodes =3D=3D NULL) { + fprintf(stderr, "could not lookup keycode name\n"); + } else if (strstart(keycodes, "evdev", NULL)) { + has_evdev =3D 1; + } else if (!strstart(keycodes, "xfree86", NULL)) { + fprintf(stderr, "unknown keycodes `%s', please report to " + "qemu-devel@nongnu.org\n", keycodes); + } + } =20 + if (desc) { + XkbFreeKeyboard(desc, XkbGBN_AllComponentsMask, True); + } + if (keycodes) { + XFree(keycodes); + } return has_evdev; } #else --------------enigF35DAD1B6966B742823D53F5 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iEYEARECAAYFAkpF0XAACgkQniDOoMHTA+lVawCfahRyqJ85rfBsMO8vpHHhEk4C 4ZoAnjlYWDvb2BCzw9I0StOG9FYBh4M7 =hHMv -----END PGP SIGNATURE----- --------------enigF35DAD1B6966B742823D53F5--