From patchwork Tue Feb 1 15:15:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 12732040 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 40318C433F5 for ; Tue, 1 Feb 2022 17:05:05 +0000 (UTC) Received: from localhost ([::1]:56424 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEwaW-0005Gj-23 for qemu-devel@archiver.kernel.org; Tue, 01 Feb 2022 12:05:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEusy-0004eC-GA for qemu-devel@nongnu.org; Tue, 01 Feb 2022 10:16:04 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:36810) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEusu-00029e-5O for qemu-devel@nongnu.org; Tue, 01 Feb 2022 10:16:00 -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-364-8SbFdvbPN3WRtlrznFAQ_g-1; Tue, 01 Feb 2022 10:15:39 -0500 X-MC-Unique: 8SbFdvbPN3WRtlrznFAQ_g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 50EAF51082; Tue, 1 Feb 2022 15:15:38 +0000 (UTC) Received: from bahia.redhat.com (unknown [10.39.192.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0177810A4B2B; Tue, 1 Feb 2022 15:15:36 +0000 (UTC) From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH v3 2/2] tests/9pfs: Use g_autofree and g_autoptr where possible Date: Tue, 1 Feb 2022 16:15:08 +0100 Message-Id: <20220201151508.190035-3-groug@kaod.org> In-Reply-To: <20220201151508.190035-1-groug@kaod.org> References: <20220201151508.190035-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Received-SPF: softfail client-ip=205.139.111.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, T_SCC_BODY_TEXT_LINE=-0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" It is recommended to use g_autofree or g_autoptr as it reduces the odds of introducing memory leaks in future changes. Signed-off-by: Greg Kurz --- tests/qtest/libqos/virtio-9p.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c index 5d18e5eae544..f51f0635cc0c 100644 --- a/tests/qtest/libqos/virtio-9p.c +++ b/tests/qtest/libqos/virtio-9p.c @@ -41,7 +41,7 @@ void virtio_9p_create_local_test_dir(void) { g_assert(local_test_path == NULL); struct stat st; - char *pwd = g_get_current_dir(); + g_autofree char *pwd = g_get_current_dir(); /* * template gets cached into local_test_path and freed in * virtio_9p_remove_local_test_dir(). @@ -52,7 +52,6 @@ void virtio_9p_create_local_test_dir(void) if (!local_test_path) { g_test_message("mkdtemp('%s') failed: %s", template, strerror(errno)); } - g_free(pwd); g_assert(local_test_path != NULL); @@ -65,12 +64,11 @@ void virtio_9p_create_local_test_dir(void) void virtio_9p_remove_local_test_dir(void) { g_assert(local_test_path != NULL); - char *cmd = g_strdup_printf("rm -fr '%s'\n", local_test_path); + g_autofree char *cmd = g_strdup_printf("rm -fr '%s'\n", local_test_path); int res = system(cmd); if (res < 0) { /* ignore error, dummy check to prevent compiler error */ } - g_free(cmd); g_free(local_test_path); local_test_path = NULL; } @@ -216,8 +214,8 @@ static void *virtio_9p_pci_create(void *pci_bus, QGuestAllocator *t_alloc, static void regex_replace(GString *haystack, const char *pattern, const char *replace_fmt, ...) { - GRegex *regex; - char *replace, *s; + g_autoptr(GRegex) regex = NULL; + g_autofree char *replace = NULL, *s = NULL; va_list argp; va_start(argp, replace_fmt); @@ -227,9 +225,6 @@ static void regex_replace(GString *haystack, const char *pattern, regex = g_regex_new(pattern, 0, 0, NULL); s = 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); } void virtio_9p_assign_local_driver(GString *cmd_line, const char *args)