From nobody Sun May 5 12:32:29 2024 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 1643217898853788.4968446386437; Wed, 26 Jan 2022 09:24:58 -0800 (PST) Received: from localhost ([::1]:35226 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nCm2T-0001TM-LJ for importer@patchew.org; Wed, 26 Jan 2022 12:24:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39956) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nClpk-00045G-Ch for qemu-devel@nongnu.org; Wed, 26 Jan 2022 12:11:53 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:41081) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nClpi-0001OM-1z for qemu-devel@nongnu.org; Wed, 26 Jan 2022 12:11:47 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-313-cniQWjvfOzKDGXvi6JSRmw-1; Wed, 26 Jan 2022 12:11:40 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3B93E1083F61; Wed, 26 Jan 2022 17:11:39 +0000 (UTC) Received: from bahia.redhat.com (unknown [10.39.192.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8045D708D9; Wed, 26 Jan 2022 17:11:37 +0000 (UTC) X-MC-Unique: cniQWjvfOzKDGXvi6JSRmw-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH] tests/9pfs: Use g_autofree and g_autoptr where possible Date: Wed, 26 Jan 2022 18:11:36 +0100 Message-Id: <20220126171136.672657-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: quoted-printable 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: softfail client-ip=207.211.30.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no 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: , Cc: Laurent Vivier , Paolo Bonzini , Thomas Huth , Christian Schoenebeck , Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1643217901806100001 Content-Type: text/plain; charset="utf-8" The template pointer in virtio_9p_create_local_test_dir() is leaked. Add the g_autofree annotation to fix that. While here, convert the rest of the virtio 9p test code to using g_autofree or g_autoptr where possible, since this is the preferred approach to avoid potential leaks in the future. Based-on: Signed-off-by: Greg Kurz Reviewed-by: Thomas Huth --- tests/qtest/libqos/virtio-9p.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c index ef96ef006adc..0a0d0d16709b 100644 --- a/tests/qtest/libqos/virtio-9p.c +++ b/tests/qtest/libqos/virtio-9p.c @@ -40,14 +40,13 @@ static char *concat_path(const char* a, const char* b) void virtio_9p_create_local_test_dir(void) { struct stat st; - char *pwd =3D g_get_current_dir(); - char *template =3D concat_path(pwd, "qtest-9p-local-XXXXXX"); + g_autofree char *pwd =3D g_get_current_dir(); + g_autofree char *template =3D concat_path(pwd, "qtest-9p-local-XXXXXX"= ); =20 local_test_path =3D mkdtemp(template); if (!local_test_path) { g_test_message("mkdtemp('%s') failed: %s", template, strerror(errn= o)); } - g_free(pwd); =20 g_assert(local_test_path !=3D NULL); =20 @@ -60,12 +59,11 @@ void virtio_9p_create_local_test_dir(void) void virtio_9p_remove_local_test_dir(void) { g_assert(local_test_path !=3D NULL); - char *cmd =3D g_strdup_printf("rm -fr '%s'\n", local_test_path); + g_autofree char *cmd =3D g_strdup_printf("rm -fr '%s'\n", local_test_p= ath); int res =3D system(cmd); if (res < 0) { /* ignore error, dummy check to prevent compiler error */ } - g_free(cmd); } =20 char *virtio_9p_test_path(const char *path) @@ -209,8 +207,8 @@ static void *virtio_9p_pci_create(void *pci_bus, QGuest= Allocator *t_alloc, static void regex_replace(GString *haystack, const char *pattern, const char *replace_fmt, ...) { - GRegex *regex; - char *replace, *s; + g_autoptr(GRegex) regex =3D NULL; + g_autofree char *replace =3D NULL, *s =3D NULL; va_list argp; =20 va_start(argp, replace_fmt); @@ -220,9 +218,6 @@ static void regex_replace(GString *haystack, const char= *pattern, regex =3D g_regex_new(pattern, 0, 0, NULL); s =3D g_regex_replace(regex, haystack->str, -1, 0, replace, 0, NULL); g_string_assign(haystack, s); - g_free(s); - g_regex_unref(regex); - g_free(replace); } =20 void virtio_9p_assign_local_driver(GString *cmd_line, const char *args) --=20 2.34.1