From nobody Tue May 13 18:39:37 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 1530481555966985.705017325825; Sun, 1 Jul 2018 14:45:55 -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 EC3DD8762E; Sun, 1 Jul 2018 21:45:54 +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 B749B60BE7; Sun, 1 Jul 2018 21:45:54 +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 5BE1B1800B6C; Sun, 1 Jul 2018 21:45:54 +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 w61Ljew1009739 for ; Sun, 1 Jul 2018 17:45:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3644260BE3; Sun, 1 Jul 2018 21:45:40 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 945D260BE7 for ; Sun, 1 Jul 2018 21:45:38 +0000 (UTC) Received: from mail-pl0-f42.google.com (mail-pl0-f42.google.com [209.85.160.42]) (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 F1C5A30E6870 for ; Sun, 1 Jul 2018 21:45:27 +0000 (UTC) Received: by mail-pl0-f42.google.com with SMTP id t6-v6so6949096plo.7 for ; Sun, 01 Jul 2018 14:45:27 -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.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Jul 2018 14:45:26 -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=m2TQIlp8ao8fsMleA2Bt/rGpAdS7T4vIQMPKwZx1jd4=; b=NXUsGLm8cCM5x8/zo8NI0qddToS+XqL9s7AK4Qaw3Rw32b/93bKgyKki0GW5ZsvgBh 2MYYH/ciVIas2YLx5f8VrxxlvlwYgxiApiuWzK16jk2bM5a7MkhYG5M93iBszSg/gapV oE0Zevfy+lwk/u1wq4zFziH1bhBe2yJpgtnGLgKMJZXG0yLBsJFgSxpQvjXFp1LHXn6J N73vCh4Z4SH/lgVc/cPTU7xZCSa5ep63ZtBg83NbNdNHCHBvZV99rU8foLwyFja0pLjh UernjIVwNWLP1JvyTDNo9EXIdQc/xSRP4dY0+81Z1H88mbEU0ln7n82jT32ze7NUdM9p YkZg== 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=m2TQIlp8ao8fsMleA2Bt/rGpAdS7T4vIQMPKwZx1jd4=; b=LYCOlXtiqIiaTfEncLqGF3Nm4pQtnZOs/FSkkn8hhLOyfpWIBkd2I7iY+9f4iu/Tt0 2TzT1kWfGlPwriCxfZoXdEL5Bn7YkEZRP36OgfrCpkLqXr/GHLLlE7v6x2KsxGC1U2ND n4MRv3Z2IoxlCOXzpjubbiZQ+yqKpTqQhJYbEztxCccuTTznTtmpmPq6f+ylT5dGZtpo 5+1cU2BZci9vaseDopINcbfxt7RWKRHNO0tGbIMBivXmvYax79QQNEgq3B2gGhLRybfO JMjCDFYBtDCsNQ3BQbsJmjcn48ghM22+1vv3xAKoqsN+otbF4AP7WEUrPhO7B/q2U203 H3fQ== X-Gm-Message-State: APt69E1AGiiOO7syXYb8C/PXWljbYHUa0ufRryl/rm4Fczdd3IyZw8hs q4EuU/NNyisO9bTTeRwRgyfpZOze X-Google-Smtp-Source: ADUXVKJ+rQZPg0IjeiQ/mXE58uUho0zYZkjHta604rgcnJ6beaANoYb20BKR3BA6xkXbZbfnjj973A== X-Received: by 2002:a17:902:8486:: with SMTP id c6-v6mr23033199plo.283.1530481527247; Sun, 01 Jul 2018 14:45:27 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 30 Jun 2018 14:30:39 +0530 Message-Id: <1530349239-22049-36-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.46]); Sun, 01 Jul 2018 21:45:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sun, 01 Jul 2018 21:45:28 +0000 (UTC) for IP:'209.85.160.42' DOMAIN:'mail-pl0-f42.google.com' HELO:'mail-pl0-f42.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.42 mail-pl0-f42.google.com 209.85.160.42 mail-pl0-f42.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 35/35] util: identity: 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.26]); Sun, 01 Jul 2018 21:45:55 +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/viridentity.c | 52 +++++++++++++++++++++-------------------------= ---- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/src/util/viridentity.c b/src/util/viridentity.c index 2f4307b..c621444 100644 --- a/src/util/viridentity.c +++ b/src/util/viridentity.c @@ -133,8 +133,8 @@ int virIdentitySetCurrent(virIdentityPtr ident) */ virIdentityPtr virIdentityGetSystem(void) { - char *username =3D NULL; - char *groupname =3D NULL; + VIR_AUTOFREE(char *) username =3D NULL; + VIR_AUTOFREE(char *) groupname =3D NULL; unsigned long long startTime; virIdentityPtr ret =3D NULL; #if WITH_SELINUX @@ -154,14 +154,14 @@ virIdentityPtr virIdentityGetSystem(void) goto error; =20 if (!(username =3D virGetUserName(geteuid()))) - goto cleanup; + return ret; if (virIdentitySetUNIXUserName(ret, username) < 0) goto error; if (virIdentitySetUNIXUserID(ret, getuid()) < 0) goto error; =20 if (!(groupname =3D virGetGroupName(getegid()))) - goto cleanup; + return ret; if (virIdentitySetUNIXGroupName(ret, groupname) < 0) goto error; if (virIdentitySetUNIXGroupID(ret, getgid()) < 0) @@ -172,7 +172,7 @@ virIdentityPtr virIdentityGetSystem(void) if (getcon(&con) < 0) { virReportSystemError(errno, "%s", _("Unable to lookup SELinux process conte= xt")); - goto cleanup; + return ret; } if (virIdentitySetSELinuxContext(ret, con) < 0) { freecon(con); @@ -182,15 +182,11 @@ virIdentityPtr virIdentityGetSystem(void) } #endif =20 - cleanup: - VIR_FREE(username); - VIR_FREE(groupname); return ret; =20 error: virObjectUnref(ret); - ret =3D NULL; - goto cleanup; + return NULL; } =20 =20 @@ -461,15 +457,14 @@ int virIdentitySetUNIXUserName(virIdentityPtr ident, int virIdentitySetUNIXUserID(virIdentityPtr ident, uid_t uid) { - char *val; - int ret; + VIR_AUTOFREE(char *) val =3D NULL; + if (virAsprintf(&val, "%d", (int)uid) < 0) return -1; - ret =3D virIdentitySetAttr(ident, + + return virIdentitySetAttr(ident, VIR_IDENTITY_ATTR_UNIX_USER_ID, val); - VIR_FREE(val); - return ret; } =20 =20 @@ -485,45 +480,42 @@ int virIdentitySetUNIXGroupName(virIdentityPtr ident, int virIdentitySetUNIXGroupID(virIdentityPtr ident, gid_t gid) { - char *val; - int ret; + VIR_AUTOFREE(char *) val =3D NULL; + if (virAsprintf(&val, "%d", (int)gid) < 0) return -1; - ret =3D virIdentitySetAttr(ident, + + return virIdentitySetAttr(ident, VIR_IDENTITY_ATTR_UNIX_GROUP_ID, val); - VIR_FREE(val); - return ret; } =20 =20 int virIdentitySetUNIXProcessID(virIdentityPtr ident, pid_t pid) { - char *val; - int ret; + VIR_AUTOFREE(char *) val =3D NULL; + if (virAsprintf(&val, "%lld", (long long) pid) < 0) return -1; - ret =3D virIdentitySetAttr(ident, + + return virIdentitySetAttr(ident, VIR_IDENTITY_ATTR_UNIX_PROCESS_ID, val); - VIR_FREE(val); - return ret; } =20 =20 int virIdentitySetUNIXProcessTime(virIdentityPtr ident, unsigned long long timestamp) { - char *val; - int ret; + VIR_AUTOFREE(char *) val =3D NULL; + if (virAsprintf(&val, "%llu", timestamp) < 0) return -1; - ret =3D virIdentitySetAttr(ident, + + return virIdentitySetAttr(ident, VIR_IDENTITY_ATTR_UNIX_PROCESS_TIME, val); - VIR_FREE(val); - return ret; } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list