From nobody Mon Feb 9 18:59:54 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 1532175242558656.632939494866; Sat, 21 Jul 2018 05:14:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3EFBB30832D3; Sat, 21 Jul 2018 12:14: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 03146308BDAC; Sat, 21 Jul 2018 12:14:01 +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 AC5461841C4B; Sat, 21 Jul 2018 12:14:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC9BuZ016677 for ; Sat, 21 Jul 2018 08:09:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id EFD53608F7; Sat, 21 Jul 2018 12:09:11 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E5101608F8 for ; Sat, 21 Jul 2018 12:08:57 +0000 (UTC) Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (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 825833081244 for ; Sat, 21 Jul 2018 12:08:46 +0000 (UTC) Received: by mail-pg1-f179.google.com with SMTP id n7-v6so8961581pgq.4 for ; Sat, 21 Jul 2018 05:08:46 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:45 -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=yHtLLI/+XTf9vQmuGLQnxQQQ+K1W+Ydr1PQDtUL3icE=; b=UxXZko7FuTz7n9W32QKvX/2qEfAG0pwPgQ4OZw8xfMrH4gLA75oeb7WagbuXjDWI1n ZpaDpc+2XZ4w66BZCAysWYvAxem6/CSzyAca8Zd86JWxXobpJ/2Vbm41WhR1O5FqJrtY V6f04YaN0oummuDTcguQDr91Vb28HoA9hx6ZOGUkP9LL2qWKTihlmK1JSTi+8evttwbH MMUN7azAv1Ka0eUnol5B8e26/BQCMCasQlwshSj9FXSUK0BVzcjcbOscCKdXrEIjEhTE 70Te+DHmonyD8P7UUK2EVoDkooVvVA5MUXh5d8lzgqLwFFxGXkSVZ13MX8+KRY5zksqr 9kdg== 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=yHtLLI/+XTf9vQmuGLQnxQQQ+K1W+Ydr1PQDtUL3icE=; b=NFL8BxcmC44ZtiqOuY19cAWoZFMHJoFuMSQDow7knHl3TjGYEeZ5aZxRIdf5wQtiLX o/EVYcw1mlT8q3yfTbJGrWh7I2ab68nzb9urRGxYasiCFUFdQnqFCAtJCG7x8TlttZVY PBsa2her0qHZNIQlz8ImgiYMkfkETUehlu11jDbUpP0kl5wYFnO6LIlYSVLftOzDe5IL R8ESWm01yQIKg2THXseNHVTJ+LRGDD+TmyRBTIAWXS5vi5P3kATq4WKo6zMPdSRdHVmc pZELCBB7dHqx5ePYLKhTm9rqqiDcxxIfsJxK1NwIBYi/fobxecJEviCa10yOrmu1jbJf k7lA== X-Gm-Message-State: AOUpUlH0Pmjyll7Em3gm6jPdY4fOd0cCAJXGyX2iGBVUc+qjWjDp/HrU afFUwVp1bX+MBaSUbIHF6wu6aIHD X-Google-Smtp-Source: AAOMgpcpwzZ4+l+zMvua51k56AB57s9l6v/wtEHTosC+fr2Uw6pCYNCypuMfX80EpFCl7jozyy3QVA== X-Received: by 2002:a63:7b1b:: with SMTP id w27-v6mr5234440pgc.199.1532174925815; Sat, 21 Jul 2018 05:08:45 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:37:05 +0530 Message-Id: <1532174832-21644-34-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-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.49]); Sat, 21 Jul 2018 12:08:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sat, 21 Jul 2018 12:08:46 +0000 (UTC) for IP:'209.85.215.179' DOMAIN:'mail-pg1-f179.google.com' HELO:'mail-pg1-f179.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.215.179 mail-pg1-f179.google.com 209.85.215.179 mail-pg1-f179.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 33/40] 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.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Sat, 21 Jul 2018 12:14: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