From nobody Tue Sep 9 19:04:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1753104403; cv=none; d=zohomail.com; s=zohoarc; b=fmi2jO2U0pzEQeyBHpXjKsAZ6PxEINNeTZ5ickk8h5IVPjq9r5QgAbZb+6eD3VQLAzMKGaXOW4hwNmaKy40uIf0AqlMxNrxzsffo2z1EFOiBFmtxpfbCkpVN9vh+qNMy0SsAGyok9dKjm5ApFubkB4wsyL6CTLwvhIBXJAAqW/A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104403; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=tSLLjy2rvwf+60LZpupw22RlHv+aYIqyVp2yhATueew=; b=U0vwdtk37417OVfWf+Z5mie2H3e9+MlOdJOBpkmjhRmj11ZPufXczejd2VEUnu5PTKK/5aPxfBlCn1JnFt0G2jPoxJOYI41gAhgfHgj9j/akZDe7Lh0ev6D04eS6DiSQ1PrmuA6xS7oXq4HueBw0mD3I4bU9tXywiXWDuAp/tgg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 17531044038251007.8682355297125; Mon, 21 Jul 2025 06:26:43 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id C2C3214C7; Mon, 21 Jul 2025 09:26:42 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 6B9FF12F8; Mon, 21 Jul 2025 09:21:50 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id D2C9EE5A; Mon, 21 Jul 2025 09:21:44 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 50A431406 for ; Mon, 21 Jul 2025 09:21:22 -0400 (EDT) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-131-8ra6ExuaM-iJe1gq5qtjjw-1; Mon, 21 Jul 2025 09:21:19 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 04FA918009CA for ; Mon, 21 Jul 2025 13:21:19 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.44.22.25]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 47543180035E for ; Mon, 21 Jul 2025 13:21:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1753104082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Vbyj9Jw6iVF+C7urM+SZgxiFYeUOS1eCzh6c5c7LILo=; b=jRPlnSHIKAoxjSnuAHnE81/CaV3gxm4Nc2HgZLPC8r44AwCxJJxmGEDj8rDuT4fxQh/dVC gZ99nSLCmR0S5wDhVkX3m6AhPro2QInSqV9GzvUS2Ki7iihHbuKKx5f/eDm54Ip7P0NnpT fAxcvuoh3b8zZAZysTi1JJSge1H12gk= X-MC-Unique: 8ra6ExuaM-iJe1gq5qtjjw-1 X-Mimecast-MFC-AGG-ID: 8ra6ExuaM-iJe1gq5qtjjw_1753104079 To: devel@lists.libvirt.org Subject: [PATCH 13/19] virSecuritySELinuxGenNewContext: Refactor cleanup Date: Mon, 21 Jul 2025 15:20:54 +0200 Message-ID: <4aa239841ed1f61f21d8beedcdb7c8e709b23bbc.1753103831.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: qnyRX9CSZa2M85J604XOiXFbY8azX3pmrJ2itBkCpj8_1753104079 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 5TURO4373AYW77JGC5N74NNH26NG3PRJ X-Message-ID-Hash: 5TURO4373AYW77JGC5N74NNH26NG3PRJ X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1753104405696116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Use automatic freeing of temporary variables and remove cleanup section. Signed-off-by: Peter Krempa --- src/security/security_selinux.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 55a5593fa5..67d9da461a 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -650,11 +650,10 @@ virSecuritySELinuxGenNewContext(const char *baseconte= xt, const char *mcs, bool isObjectContext) { - context_t context =3D NULL; - char *ret =3D NULL; + g_autoptr(context_s_t) context =3D NULL; const char *str; - char *ourSecContext =3D NULL; - context_t ourContext =3D NULL; + g_autofree char *ourSecContext =3D NULL; + g_autoptr(context_s_t) ourContext =3D NULL; VIR_DEBUG("basecontext=3D%s mcs=3D%s isObjectContext=3D%d", basecontext, mcs, isObjectContext); @@ -662,13 +661,13 @@ virSecuritySELinuxGenNewContext(const char *baseconte= xt, if (getcon_raw(&ourSecContext) < 0) { virReportSystemError(errno, "%s", _("Unable to get current process SELinux cont= ext")); - goto cleanup; + return NULL; } if (!(ourContext =3D context_new(ourSecContext))) { virReportSystemError(errno, _("Unable to parse current SELinux context '%= 1$s'"), ourSecContext); - goto cleanup; + return NULL; } VIR_DEBUG("process=3D%s", ourSecContext); @@ -676,7 +675,7 @@ virSecuritySELinuxGenNewContext(const char *basecontext, virReportSystemError(errno, _("Unable to parse base SELinux context '%1$s= '"), basecontext); - goto cleanup; + return NULL; } if (context_user_set(context, @@ -684,7 +683,7 @@ virSecuritySELinuxGenNewContext(const char *basecontext, virReportSystemError(errno, _("Unable to set SELinux context user '%1$s'"= ), context_user_get(ourContext)); - goto cleanup; + return NULL; } if (!isObjectContext && @@ -693,27 +692,23 @@ virSecuritySELinuxGenNewContext(const char *baseconte= xt, virReportSystemError(errno, _("Unable to set SELinux context role '%1$s'"= ), context_role_get(ourContext)); - goto cleanup; + return NULL; } if (context_range_set(context, mcs) !=3D 0) { virReportSystemError(errno, _("Unable to set SELinux context MCS '%1$s'"), mcs); - goto cleanup; + return NULL; } if (!(str =3D context_str(context))) { virReportSystemError(errno, "%s", _("Unable to format SELinux context")); - goto cleanup; + return NULL; } - ret =3D g_strdup(str); - VIR_DEBUG("Generated context '%s'", ret); - cleanup: - freecon(ourSecContext); - context_free(ourContext); - context_free(context); - return ret; + + VIR_DEBUG("Generated context '%s'", str); + return g_strdup(str); } --=20 2.50.0