From nobody Tue May 13 22:25:36 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 1528400168148847.8172209532081; Thu, 7 Jun 2018 12:36:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 11BE1308A95E; Thu, 7 Jun 2018 19:36:07 +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 D06DC600C9; Thu, 7 Jun 2018 19:36:06 +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 63819180BA83; Thu, 7 Jun 2018 19:36:06 +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 w57JZtqL019145 for ; Thu, 7 Jun 2018 15:35:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5578B60E37; Thu, 7 Jun 2018 19:35:55 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4BBD160C4E for ; Thu, 7 Jun 2018 19:35:49 +0000 (UTC) Received: from mail-pf0-f194.google.com (mail-pf0-f194.google.com [209.85.192.194]) (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 63D4380F8F for ; Thu, 7 Jun 2018 19:35:37 +0000 (UTC) Received: by mail-pf0-f194.google.com with SMTP id a11-v6so5394744pff.8 for ; Thu, 07 Jun 2018 12:35:37 -0700 (PDT) Received: from centos.localdomain ([49.32.106.159]) by smtp.gmail.com with ESMTPSA id d23-v6sm86686407pfn.3.2018.06.07.12.35.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jun 2018 12:35:34 -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=kajc04scwxEqmm78RcfxJEb6zXVtQchxVL8RTp3ttYU=; b=YqucLRdZ0YEsid0tR2iGm3hOCpXTp1x4fuMIChFV4l7ZvUF3RhMH8wrCBF2SVkR9VK eJXVs/FxaBtkl7Eyn+IbGzlPIzK5XTqnFrvq7ak6YyY5qDekOeNtStQX1hJoMTbpU2cJ B2p/h96fDzyWJnA2azWSU7pJuBNZhy9nHfG+vqxeXRcDR45XD5teM+u0SdaD1KWKre/1 SG5g9fTw37Gil9Lsr+aWfIph4Zq6koOkFxWsa2C+r0PyJClJVrKyFJqgZBCEAAgPyju8 ayhDuXABPbzP/X26KzVorw5B+EACJYQ+vQ4WG4Jun4LXoO7GfSKqJsQNIXI5jSznE+bY S3Cg== 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=kajc04scwxEqmm78RcfxJEb6zXVtQchxVL8RTp3ttYU=; b=nBxwfxKFvf8Ka+BRmqwyDoDyhJQrXG0PuG509YgvlujCrzF+J1Wbxa0UTDcROjU09d wXFroeQEAT1rZqd3mLIUicIM1DZuwAKTI+HMs7Y1B2loebFjKnMwP7bdGjm466NE6ASD a0Vp5KwPOhHisJlmMLoRQFNfs0qO0QcAJluiNoixKpEMDCtHnpEBzjwxZ1V9hFfWAeCd m3gWRFYf31lF8Njg9Le7sXWk/guk+tV2h8S+0/vzpjhG9H8NS61OzMRs2U9vufk3zgWr iA81RwkXNWP5DvjB9lTaiwOAyRUZ5BhT9zwBhTXkG/akWm/laukULGJpfvAS3L1JRHHN eOIA== X-Gm-Message-State: APt69E38mP1zO0lLfpZ/Tul6XIWR/qZLHtn4U/LJ5foVepgzNiBZ0fWW f4OmFPTeKIB/4O4mOZpUwUfnT0HW X-Google-Smtp-Source: ADUXVKIm10oMYwt7tjyHLLVnB1j8pxXVgQ9Nh5LodBK/SXPOoyzf1MzmxemXfJT2iw85eMoxAeOq2Q== X-Received: by 2002:a62:cf44:: with SMTP id b65-v6mr2953863pfg.80.1528400134654; Thu, 07 Jun 2018 12:35:34 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 8 Jun 2018 01:04:40 +0530 Message-Id: <1528400083-6788-19-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528400083-6788-1-git-send-email-skrtbhtngr@gmail.com> References: <1528400083-6788-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.27]); Thu, 07 Jun 2018 19:35:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 07 Jun 2018 19:35:37 +0000 (UTC) for IP:'209.85.192.194' DOMAIN:'mail-pf0-f194.google.com' HELO:'mail-pf0-f194.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.511 (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.194 mail-pf0-f194.google.com 209.85.192.194 mail-pf0-f194.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 18/21] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 07 Jun 2018 19:36:07 +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 the GCC's __attribute__((cleanup)) handled by VIR_AUTOFREE macro, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. --- src/util/viridentity.c | 54 ++++++++++++++++++++--------------------------= ---- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/src/util/viridentity.c b/src/util/viridentity.c index 2f4307b..2060dd7 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,9 @@ virIdentityPtr virIdentityGetSystem(void) } #endif =20 - cleanup: - VIR_FREE(username); - VIR_FREE(groupname); - return ret; - error: virObjectUnref(ret); - ret =3D NULL; - goto cleanup; + return NULL; } =20 =20 @@ -461,15 +455,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 +478,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