From nobody Mon Feb 9 07:04:35 2026 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 1531504596183617.0560443527153; Fri, 13 Jul 2018 10:56:36 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 10EEB804E5; Fri, 13 Jul 2018 17:56:34 +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 AA9BEC6A35; Fri, 13 Jul 2018 17:56:33 +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 3904E1800B6D; Fri, 13 Jul 2018 17:56:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6DHuWtk009044 for ; Fri, 13 Jul 2018 13:56:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id F37852010D5C; Fri, 13 Jul 2018 17:56:31 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EA4EE2010D5B for ; Fri, 13 Jul 2018 17:56:31 +0000 (UTC) Received: from mail-pf0-f193.google.com (mail-pf0-f193.google.com [209.85.192.193]) (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 D341D859FF for ; Fri, 13 Jul 2018 17:56:20 +0000 (UTC) Received: by mail-pf0-f193.google.com with SMTP id s21-v6so23065966pfm.6 for ; Fri, 13 Jul 2018 10:56:20 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.56.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:56:19 -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=lHbvp/ZiQyuZnIt0imUW6X8BQrcSvQ7Kkga3zR5TcTI=; b=c0XdPrFS4oFqOXD6OGPQw4QbSg4wjbJq7/rIxFoJzfIEWOV/m0o00bUHtmf0N5K7f8 kX4dfHiyXCovuucYpyGdpFBu3OuVgoyRoDL/LPoKPY2QHEsBnoPLlnf7VbUtPlIClwEl wRumvLgbLq8yvSdh+vogaPetgjzf6eyMS509UFoKYeyyHC4/g8eJiCFpXsT0N97QtUeD TSYyjkYcAAo4pUmEJXLphcNxbxCzceTo6g337yEa2g2/DTGOn/t26bRXH4+dL05xqK6N 8YuJ5dR0topYkMvMr7io0x0+Mp7fgfozKOI+J6ARBuATDmy63LvY/eCmcmcb309epQ1i yNuQ== 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=lHbvp/ZiQyuZnIt0imUW6X8BQrcSvQ7Kkga3zR5TcTI=; b=XgLbWyByzEZTdTXQxx7EaCEhGNqE3LOZzHrIz8CQtG09CGd0FQEjTeb4DRohKrMxgU huGh0mZe7ft9VHqUUUU+ZsZKdyLBwsqM7EzmFoh6sGjJo6Z3TV3qkFUxzijwGe02Ym35 dtDodu9cwjfGIGEsQgYYDJYDfnfWVK5K2xFf4iv9eRybHyiTwmADaBmZyrrEueOxURiw dF+Va7Av+XyHGRSaMHC6IXiBtrpDhV9JKXVnRv2+OD0rhuqJ/9GshJ9neiG5q0NATByT PVHDeCGmP9KnRuJt4K+ZEdLvwfWDT8mo4ql7qO+i7NJ4wj+7gOvK6jyVOY1/OhMcBWmX CSLQ== X-Gm-Message-State: AOUpUlFhBGkH5ipolUZnXoPr69ZaAd7LXB3yfVOK6hpXCh1YubbWNZC2 CU/RvUCdvqhr/lo3JS7Vm3X+/oal X-Google-Smtp-Source: AAOMgpdIAs+GJo1oyFsZhCM2VZuZUU91WlxMIAwcyO7R3kKMbhLFvTv4KBUwU++9xA1Kozak3eWSvA== X-Received: by 2002:a65:520d:: with SMTP id o13-v6mr6923200pgp.282.1531504580096; Fri, 13 Jul 2018 10:56:20 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:25:08 +0530 Message-Id: <1531504509-7930-31-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1531504509-7930-1-git-send-email-skrtbhtngr@gmail.com> References: <1531504509-7930-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.26]); Fri, 13 Jul 2018 17:56:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 13 Jul 2018 17:56:20 +0000 (UTC) for IP:'209.85.192.193' DOMAIN:'mail-pf0-f193.google.com' HELO:'mail-pf0-f193.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.3 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.192.193 mail-pf0-f193.google.com 209.85.192.193 mail-pf0-f193.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 30/31] 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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 13 Jul 2018 17:56:35 +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 Reviewed-by: Erik Skultety --- 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; + return NULL; =20 - file =3D virBufferContentAndReset(&buf); - - 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; + return -1; =20 - ret =3D 0; - - 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