From nobody Tue May 13 11:48:21 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 15326391629131001.0851823642405; Thu, 26 Jul 2018 14:06:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 106BA3084053; Thu, 26 Jul 2018 21:06:01 +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 A33E960C9A; Thu, 26 Jul 2018 21:06:00 +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 2F3CE1800B77; Thu, 26 Jul 2018 21:06:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6QL5qpQ025064 for ; Thu, 26 Jul 2018 17:05:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id A180A5D750; Thu, 26 Jul 2018 21:05:52 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9628F5D6A5 for ; Thu, 26 Jul 2018 21:05:52 +0000 (UTC) Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (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 E13DC3084051 for ; Thu, 26 Jul 2018 21:05:44 +0000 (UTC) Received: by mail-pg1-f181.google.com with SMTP id f1-v6so1876401pgq.12 for ; Thu, 26 Jul 2018 14:05:44 -0700 (PDT) Received: from centos.localdomain ([42.106.3.93]) by smtp.gmail.com with ESMTPSA id z10-v6sm3279182pfh.83.2018.07.26.14.05.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 14:05:43 -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=0/U6X9PGjT7KCXpDmFXlDYr9tnkwv90tvmfCZLAke7A=; b=OhY9rVTQJEBk3QvXVkF2DujVm5IoFxvTAETRDQRuGCoWShJ5b6xhikTplNSejy6BQY 39mUGVK+toruUlwtLFDKv+g35Tu7n8W14B53plJ5wgBt/y7SwbEnSe20YoH3VmqXlV9Q 3IJvNmWQVdZYJCHxiJyqvIN95K8bCd8jla1MZ1QlQ2C+30Xqt4G6BP5ha1vglHNIhFvo tDnrKWWHb6i+fwK1t2tny0xBfDxUpkYt9C0rxUtjMBO3rLLzngIn/Lh5GixdPEHthy3D iNv87j/vlwi9i3l8QGusAW5Qvr4TGnttdzkYN1bwiMCHX+5ManiT9Vu/vPh9OmcS4ekH rhug== 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=0/U6X9PGjT7KCXpDmFXlDYr9tnkwv90tvmfCZLAke7A=; b=F0axEqoGymBhzSjhM/urYAiYvxkahSYcTZB3dQaqNvYBStQvVJDSRtaDKVENYlBUT+ 0Ku7HK/a3B++zY4Yu6FaAa4qBhf0PgN1Nn60MkzsODYXD5SatErZ6Sc88TcmTsvk8Jex 3zPfcZWKmpLG+WmulakWQV4/2YYLxkxrrB5AV4+kOSKbg9yvlG+yG5EhgyncdH8O+JBx 4PXeGQ+z8q7g4EEbSS3odnSy5FeY5JQFANGM/eQBPsn1xqfb3EqPQRl1oEQ2zuDFT5cn i2ieulwfVpCvPdzVyib0Y77ciY+YryO3xerrZFsFdFR906PliEwg2hokHFW69GDaBvBl m+4g== X-Gm-Message-State: AOUpUlFUK28nRZLBkjxrevwrwh4Foa7lYhYiffwgcIOB677wOlW84Xo0 dhD1ek9xwis8svQxisdgF77QGWxk X-Google-Smtp-Source: AAOMgpc0m0xuzKXR+0m7wJTrx9KJWCK8K8wLGFzU4n+cjqLIa+8Z1k6T7CVgDu175N436tGwAIsESw== X-Received: by 2002:a65:4c41:: with SMTP id l1-v6mr3435840pgr.310.1532639144134; Thu, 26 Jul 2018 14:05:44 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Tue, 24 Jul 2018 21:22:35 +0530 Message-Id: <1532447562-24010-35-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532447562-24010-1-git-send-email-skrtbhtngr@gmail.com> References: <1532447562-24010-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.40]); Thu, 26 Jul 2018 21:05:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 26 Jul 2018 21:05:51 +0000 (UTC) for IP:'209.85.215.181' DOMAIN:'mail-pg1-f181.google.com' HELO:'mail-pg1-f181.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.37 * (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, SPF_PASS) 209.85.215.181 mail-pg1-f181.google.com 209.85.215.181 mail-pg1-f181.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 34/41] util: hostmem: 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.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 26 Jul 2018 21:06:01 +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/virhostmem.c | 57 ++++++++++++++++-------------------------------= ---- 1 file changed, 18 insertions(+), 39 deletions(-) diff --git a/src/util/virhostmem.c b/src/util/virhostmem.c index c923a1e..08ed7a5 100644 --- a/src/util/virhostmem.c +++ b/src/util/virhostmem.c @@ -263,7 +263,7 @@ virHostMemGetStats(int cellNum ATTRIBUTE_UNUSED, #ifdef __linux__ { int ret; - char *meminfo_path =3D NULL; + VIR_AUTOFREE(char *) meminfo_path =3D NULL; FILE *meminfo; int max_node; =20 @@ -299,12 +299,10 @@ virHostMemGetStats(int cellNum ATTRIBUTE_UNUSED, if (!meminfo) { virReportSystemError(errno, _("cannot open %s"), meminfo_path); - VIR_FREE(meminfo_path); return -1; } ret =3D virHostMemGetStatsLinux(meminfo, cellNum, params, nparams); VIR_FORCE_FCLOSE(meminfo); - VIR_FREE(meminfo_path); =20 return ret; } @@ -322,45 +320,36 @@ virHostMemGetStats(int cellNum ATTRIBUTE_UNUSED, static int virHostMemSetParameterValue(virTypedParameterPtr param) { - char *path =3D NULL; - char *strval =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) strval =3D NULL; int rc =3D -1; =20 char *field =3D strchr(param->field, '_'); sa_assert(field); field++; if (virAsprintf(&path, "%s/%s", - SYSFS_MEMORY_SHARED_PATH, field) < 0) { - ret =3D -2; - goto cleanup; - } + SYSFS_MEMORY_SHARED_PATH, field) < 0) + return -2; =20 - if (virAsprintf(&strval, "%u", param->value.ui) =3D=3D -1) { - ret =3D -2; - goto cleanup; - } + if (virAsprintf(&strval, "%u", param->value.ui) =3D=3D -1) + return -2; =20 if ((rc =3D virFileWriteStr(path, strval, 0)) < 0) { virReportSystemError(-rc, _("failed to set %s"), param->field); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - VIR_FREE(strval); - return ret; + return 0; } =20 static bool virHostMemParametersAreAllSupported(virTypedParameterPtr params, int nparams) { - char *path =3D NULL; size_t i; =20 for (i =3D 0; i < nparams; i++) { + VIR_AUTOFREE(char *) path =3D NULL; virTypedParameterPtr param =3D ¶ms[i]; =20 char *field =3D strchr(param->field, '_'); @@ -374,11 +363,8 @@ virHostMemParametersAreAllSupported(virTypedParameterP= tr params, virReportError(VIR_ERR_OPERATION_INVALID, _("Parameter '%s' is not supported by " "this kernel"), param->field); - VIR_FREE(path); return false; } - - VIR_FREE(path); } =20 return true; @@ -430,23 +416,20 @@ static int virHostMemGetParameterValue(const char *field, void *value) { - char *path =3D NULL; - char *buf =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; char *tmp =3D NULL; - int ret =3D -1; int rc =3D -1; =20 if (virAsprintf(&path, "%s/%s", SYSFS_MEMORY_SHARED_PATH, field) < 0) - goto cleanup; + return -1; =20 - if (!virFileExists(path)) { - ret =3D -2; - goto cleanup; - } + if (!virFileExists(path)) + return -2; =20 if (virFileReadAll(path, 1024, &buf) < 0) - goto cleanup; + return -1; =20 if ((tmp =3D strchr(buf, '\n'))) *tmp =3D '\0'; @@ -465,14 +448,10 @@ virHostMemGetParameterValue(const char *field, if (rc < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to parse %s"), field); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - VIR_FREE(buf); - return ret; + return 0; } #endif =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list