From nobody Tue Nov 26 13:47:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1574161758; cv=none; d=zoho.com; s=zohoarc; b=F6dOvpElLs8MB/nUW+JIl86CJhOQQQ8xG/egLIC+BKO6E019Fv3CKZpK70aN2jPBUT9sPqWuotTxdk/6nkMFFK72iMTrbo2J9ZhIYdKdtFzZG5CXadLcpCPzPK3uqtqzAuY+fk+LXHfDVJmjXFRkNMpQQ0L8jUZWuhW/MAzG4tI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574161758; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LQ4g9JYzXVHA8agnIxZYdE4UF24Ny8gPVDmx4g2+g5g=; b=knvoGZAzsd8H8430iauyOYLTq/q09LxHquDwrplvAofQgSduk0zTFp3v+cRWjZQ7uJ5MeD3nuCyQc5LOApm/MU3zQdK4CxovAp78Ol6ilpHrOtyuX/8H/Z8jjhwgThkpVIyENPcENkI2zFhB2cxOGg1ZpbaDrsq1wS7Zv3UnV/o= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1574161758126348.50017597166175; Tue, 19 Nov 2019 03:09:18 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-144-nxIV9RmKPma_WO71qKbrsg-1; Tue, 19 Nov 2019 06:09:15 -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 669F71883524; Tue, 19 Nov 2019 11:09:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3EF3C46E67; Tue, 19 Nov 2019 11:09:10 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id EC3184E56C; Tue, 19 Nov 2019 11:09:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xAJB8pkx021153 for ; Tue, 19 Nov 2019 06:08:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4C3EB9302; Tue, 19 Nov 2019 11:08:51 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA80A2935D for ; Tue, 19 Nov 2019 11:08:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574161757; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=LQ4g9JYzXVHA8agnIxZYdE4UF24Ny8gPVDmx4g2+g5g=; b=PKQJmv4Q2pwQUNSS2KbFGq7iHw6b0U6A0QQpkGobTWe/Wy+CCdhSdYnI1Tx3z+6Ezzy++K 0ymI1WVe7Hn0tsGJouNBVAUfoktooyde4VycndIjIu2psHpJaZDqZACiCy7X3n1cei0fy3 N3sxjWiUDeTZgCwQh9GiaEd64KIzXEY= From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 19 Nov 2019 12:08:44 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/3] tests: schema: Simplify memory handling using g_autofree X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: nxIV9RmKPma_WO71qKbrsg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Refactor various functions to avoid multiple freeing function calls. Signed-off-by: Peter Krempa --- tests/virschematest.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/tests/virschematest.c b/tests/virschematest.c index 5d092d8c8e..8a2322b3bd 100644 --- a/tests/virschematest.c +++ b/tests/virschematest.c @@ -72,8 +72,6 @@ testSchemaDir(const char *schema, struct dirent *ent; int ret =3D 0; int rc; - char *test_name =3D NULL; - char *xml_path =3D NULL; struct testSchemaData data =3D { .validator =3D validator, }; @@ -82,6 +80,9 @@ testSchemaDir(const char *schema, return -1; while ((rc =3D virDirRead(dir, &ent, dir_path)) > 0) { + g_autofree char *test_name =3D NULL; + g_autofree char *xml_path =3D NULL; + if (!virStringHasSuffix(ent->d_name, ".xml")) continue; if (ent->d_name[0] =3D=3D '.') @@ -94,16 +95,11 @@ testSchemaDir(const char *schema, data.xml_path =3D xml_path; if (virTestRun(test_name, testSchemaFile, &data) < 0) ret =3D -1; - - VIR_FREE(test_name); - VIR_FREE(xml_path); } if (rc < 0) ret =3D -1; - VIR_FREE(test_name); - VIR_FREE(xml_path); VIR_DIR_CLOSE(dir); return ret; } @@ -114,19 +110,16 @@ testSchemaDirs(const char *schema, virXMLValidatorPtr= validator, ...) { va_list args; int ret =3D 0; - char *dir_path =3D NULL; const char *dir; va_start(args, validator); while ((dir =3D va_arg(args, char *))) { - dir_path =3D g_strdup_printf("%s/%s", abs_srcdir, dir); + g_autofree char *dir_path =3D g_strdup_printf("%s/%s", abs_srcdir,= dir); if (testSchemaDir(schema, validator, dir_path) < 0) ret =3D -1; - VIR_FREE(dir_path); } - VIR_FREE(dir_path); va_end(args); return ret; } @@ -136,20 +129,15 @@ static int testSchemaGrammar(const void *opaque) { struct testSchemaData *data =3D (struct testSchemaData *) opaque; - char *schema_path; - int ret =3D -1; + g_autofree char *schema_path =3D NULL; schema_path =3D g_strdup_printf("%s/docs/schemas/%s", abs_top_srcdir, data->schema); if (!(data->validator =3D virXMLValidatorInit(schema_path))) - goto cleanup; - - ret =3D 0; + return -1; - cleanup: - VIR_FREE(schema_path); - return ret; + return 0; } --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list