From nobody Tue Feb 10 08:06:58 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1663568764415645.2051013498026; Sun, 18 Sep 2022 23:26:04 -0700 (PDT) Received: from localhost ([::1]:59778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oaAEE-0005Kg-Kl for importer@patchew.org; Mon, 19 Sep 2022 02:26:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43754) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oaA8R-0003LX-W8 for qemu-devel@nongnu.org; Mon, 19 Sep 2022 02:20:08 -0400 Received: from mailout10.t-online.de ([194.25.134.21]:45106) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oaA8P-0006tf-8U for qemu-devel@nongnu.org; Mon, 19 Sep 2022 02:20:03 -0400 Received: from fwd77.dcpf.telekom.de (fwd77.aul.t-online.de [10.223.144.103]) by mailout10.t-online.de (Postfix) with SMTP id 52D4FCDCA; Mon, 19 Sep 2022 08:19:58 +0200 (CEST) Received: from linpower.localnet ([84.175.228.229]) by fwd77.t-online.de with (TLSv1.3:TLS_AES_256_GCM_SHA384 encrypted) esmtp id 1oaA8L-1NUYjp0; Mon, 19 Sep 2022 08:19:57 +0200 Received: by linpower.localnet (Postfix, from userid 1000) id D5E3A200613; Mon, 19 Sep 2022 08:19:56 +0200 (CEST) From: =?UTF-8?q?Volker=20R=C3=BCmelin?= To: Gerd Hoffmann Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Kshitij Suri , qemu-devel@nongnu.org Subject: [PATCH v2] ui/console: fix three double frees in png_save() Date: Mon, 19 Sep 2022 08:19:56 +0200 Message-Id: <20220919061956.30929-1-vr_qemu@t-online.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TOI-EXPURGATEID: 150726::1663568397-8A6BF81F-38F94621/0/0 CLEAN NORMAL X-TOI-MSGID: dcecec61-4d81-4fd7-b1af-351478b79d4d Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=194.25.134.21; envelope-from=volker.ruemelin@t-online.de; helo=mailout10.t-online.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1663568765986100001 The png_destroy_write_struct() function frees all memory used by libpng. Don't use the glib auto cleanup mechanism to free the memory allocated by libpng again. For the pixman image, use only the auto cleanup mechanism and remove the qemu_pixman_image_unref() function call to prevent another double free. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1210 Fixes: 9a0a119a38 ("Added parameter to take screenshot with screendump as P= NG") Tested-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Volker R=C3=BCmelin --- v2: There's no need to inititalize info_ptr with NULL. (Philippe) ui/console.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ui/console.c b/ui/console.c index 765892f84f..da179e1832 100644 --- a/ui/console.c +++ b/ui/console.c @@ -304,8 +304,8 @@ static bool png_save(int fd, pixman_image_t *image, Err= or **errp) { int width =3D pixman_image_get_width(image); int height =3D pixman_image_get_height(image); - g_autofree png_struct *png_ptr =3D NULL; - g_autofree png_info *info_ptr =3D NULL; + png_struct *png_ptr; + png_info *info_ptr; g_autoptr(pixman_image_t) linebuf =3D qemu_pixman_linebuf_create(PIXMAN_a8r8g8b8, wi= dth); uint8_t *buf =3D (uint8_t *)pixman_image_get_data(linebuf); @@ -346,7 +346,6 @@ static bool png_save(int fd, pixman_image_t *image, Err= or **errp) qemu_pixman_linebuf_fill(linebuf, image, width, 0, y); png_write_row(png_ptr, buf); } - qemu_pixman_image_unref(linebuf); =20 png_write_end(png_ptr, NULL); =20 --=20 2.35.3