From nobody Tue May 13 18:47:58 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1530481550736580.4133373534012; Sun, 1 Jul 2018 14:45:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9EBFF3084031; Sun, 1 Jul 2018 21:45:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6145416BE0; Sun, 1 Jul 2018 21:45:49 +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 EDAC01800B68; Sun, 1 Jul 2018 21:45:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w61Ljdkh009734 for ; Sun, 1 Jul 2018 17:45:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9BA5460C8C; Sun, 1 Jul 2018 21:45:39 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 944C660BE3 for ; Sun, 1 Jul 2018 21:45:36 +0000 (UTC) Received: from mail-pl0-f67.google.com (mail-pl0-f67.google.com [209.85.160.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0F1BA307D859 for ; Sun, 1 Jul 2018 21:45:26 +0000 (UTC) Received: by mail-pl0-f67.google.com with SMTP id s24-v6so6942884plq.6 for ; Sun, 01 Jul 2018 14:45:26 -0700 (PDT) Received: from centos.localdomain ([157.37.164.55]) by smtp.gmail.com with ESMTPSA id v68-v6sm15006933pfv.143.2018.07.01.14.45.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Jul 2018 14:45:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=HJ0k1Mx3lDcW/X1DmXpucpaAmDjb6UGBMBKbJgTfroY=; b=NsTFXBHnGbOyc++ucQxvpDemHwJej88WOBRCos3NoxeWTASUsav6kerYz79xnymqBw ZfQ55ybqsV3BY8a3MrSwd1CA6IfHbeo/8Ch1OtzkfWfNB1JauOpY+2ljDAdJNKwmnHTG VtaI9LG0s7wzxapRGDnEpDdF1IvRIf+RLNlSoYPJMXGOctl/qwkHr3eWb6DPf01Zh7/H 9zhYEqtOXswVIMeKoURMJnWgyX9Tc7t8mN5KX6wZUJxAlM5QN7yZpXYRDlUfp8G+Y8Qg 2kUvTxHq8iOgSgzjZJIIawmTSmxvb/+xEkXX6Ix0CM54YWTiOJFoTwiD/zInbWIkQr7Z 1gOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=HJ0k1Mx3lDcW/X1DmXpucpaAmDjb6UGBMBKbJgTfroY=; b=eW0/BURlVs6cMg7UBAe58uWnMw9F7oiUgihdK3fT0TFyAMZZHDT6FlOBuIrIsS8mD1 eynrJ4nu4wSGrOfvhRgu8swodg7CRVF9NyT/4FLJ9HDJqRZyDLAGF9IEwffMqdr5UX2P OhaJ2H0O2fhFw+Ijk/tS7n1rrL0gkSPCYA2CsXI3GS3Lt1nFZ8eepA7WiGL+SqjABD6x +vaaQsUSx3RAIZv4Bevmz6S1QB64gn8xUROwTm1Dy7bevukzbXSLHO0HHRVfdDqVzwGr oijsyo47xtxlQkFsfVryQ9tht4N66ZRRlcp7GYWhKBZMHc3iDe+dXlEqiTm97taiwnn0 wm1A== X-Gm-Message-State: APt69E19lfnn4yVD6rrVrZHdT0xQb9+V8E4JX+xiDwWbPU+yl95vnSqR L30Mrf7Ytl6PeHr6qO5hxqxNo8v4 X-Google-Smtp-Source: ADUXVKI7LbZpSb+zWNAey3iP+f9n6BJaZwu8G06X7gRt+wlaKb/5BM4xp9ihmUwrK24j72Cc7L+msw== X-Received: by 2002:a17:902:43a4:: with SMTP id j33-v6mr23388206pld.118.1530481525370; Sun, 01 Jul 2018 14:45:25 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 30 Jun 2018 14:30:38 +0530 Message-Id: <1530349239-22049-35-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1530349239-22049-1-git-send-email-skrtbhtngr@gmail.com> References: <1530349239-22049-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sun, 01 Jul 2018 21:45:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sun, 01 Jul 2018 21:45:26 +0000 (UTC) for IP:'209.85.160.67' DOMAIN:'mail-pl0-f67.google.com' HELO:'mail-pl0-f67.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.766 * (DATE_IN_PAST_24_48, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.160.67 mail-pl0-f67.google.com 209.85.160.67 mail-pl0-f67.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 34/35] util: filecache: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Sun, 01 Jul 2018 21:45:50 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virfilecache.c | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/src/util/virfilecache.c b/src/util/virfilecache.c index 96ae96d..2927c68 100644 --- a/src/util/virfilecache.c +++ b/src/util/virfilecache.c @@ -100,18 +100,17 @@ static char * virFileCacheGetFileName(virFileCachePtr cache, const char *name) { - char *file =3D NULL; - char *namehash =3D NULL; + VIR_AUTOFREE(char *) namehash =3D NULL; virBuffer buf =3D VIR_BUFFER_INITIALIZER; =20 if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, name, &namehash) < 0) - goto cleanup; + return NULL; =20 if (virFileMakePath(cache->dir) < 0) { virReportSystemError(errno, _("Unable to create directory '%s'"), cache->dir); - goto cleanup; + return NULL; } =20 virBufferAsprintf(&buf, "%s/%s", cache->dir, namehash); @@ -120,13 +119,9 @@ virFileCacheGetFileName(virFileCachePtr cache, virBufferAsprintf(&buf, ".%s", cache->suffix); =20 if (virBufferCheckError(&buf) < 0) - goto cleanup; - - file =3D virBufferContentAndReset(&buf); + return NULL; =20 - cleanup: - VIR_FREE(namehash); - return file; + return virBufferContentAndReset(&buf); } =20 =20 @@ -135,7 +130,7 @@ virFileCacheLoad(virFileCachePtr cache, const char *name, void **data) { - char *file =3D NULL; + VIR_AUTOFREE(char *) file =3D NULL; int ret =3D -1; void *loadData =3D NULL; =20 @@ -178,7 +173,6 @@ virFileCacheLoad(virFileCachePtr cache, =20 cleanup: virObjectUnref(loadData); - VIR_FREE(file); return ret; } =20 @@ -188,20 +182,15 @@ virFileCacheSave(virFileCachePtr cache, const char *name, void *data) { - char *file =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) file =3D NULL; =20 if (!(file =3D virFileCacheGetFileName(cache, name))) - return ret; + return -1; =20 if (cache->handlers.saveFile(data, file, cache->priv) < 0) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(file); - return ret; + return 0; } =20 =20 @@ -346,7 +335,7 @@ virFileCacheLookupByFunc(virFileCachePtr cache, const void *iterData) { void *data =3D NULL; - char *name =3D NULL; + VIR_AUTOFREE(char *) name =3D NULL; =20 virObjectLock(cache); =20 @@ -356,8 +345,6 @@ virFileCacheLookupByFunc(virFileCachePtr cache, virObjectRef(data); virObjectUnlock(cache); =20 - VIR_FREE(name); - return data; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list