From nobody Sun Feb 8 05:27:31 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1570704881; cv=none; d=zoho.com; s=zohoarc; b=dcaN4KFCMtwekooNvNuZM/6tO6wjSZhRtsPWGEyxAcs9iG77ajT525mBjlRywWY4OqkEMDtrATJar5Iv6kavnLHNOqiH7MoChQkJsC56e5XrRhgSWE2ssFTcKGi0oihKRYZXKYttyairr0xMka2COXm7uTWPkYk31YFYs1f+0pM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704881; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2vwzXuHJo3P25OAGcGpisZpPd24AXQOK5zdiTA27Pvo=; b=PSvB/lqiLBpioAZOHLBMJF7Tgxs+vdpmFcaxnhQtKCUAAMk0RnNRKV0hbjl9JfvNImmK695zttdToiuIeLpaaheZGTI5SzV+5LUpbDNszLSahfzBX8YuGvRCbeicwtLO1wPnx0Y3XxWwP5BotvoF5mP0aw/3niaJ+uZbk0NAvbI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570704881280694.3820492670973; Thu, 10 Oct 2019 03:54:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA04FA44AE6; Thu, 10 Oct 2019 10:54:39 +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 8D0525C1B5; Thu, 10 Oct 2019 10:54:39 +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 3A0B4180BAA2; Thu, 10 Oct 2019 10:54:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAsPcY010407 for ; Thu, 10 Oct 2019 06:54:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5E23F5C22F; Thu, 10 Oct 2019 10:54:25 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADFA45C1B5; Thu, 10 Oct 2019 10:54:24 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:54:02 +0100 Message-Id: <20191010105413.4091-9-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= Subject: [libvirt] [PATCH v3 08/19] conf: convert virSecretObj APIs to use autofree 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: , Content-Type: text/plain; charset="utf-8" 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Thu, 10 Oct 2019 10:54:40 +0000 (UTC) Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel P. Berrang=C3=A9 --- src/conf/virsecretobj.c | 46 +++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 7800912bff..aeae82332b 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -678,43 +678,33 @@ virSecretObjDeleteData(virSecretObjPtr obj) int virSecretObjSaveConfig(virSecretObjPtr obj) { - char *xml =3D NULL; - int ret =3D -1; + g_autofree char *xml =3D NULL; =20 if (!(xml =3D virSecretDefFormat(obj->def))) - goto cleanup; + return -1; =20 if (virFileRewriteStr(obj->configFile, S_IRUSR | S_IWUSR, xml) < 0) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(xml); - return ret; + return 0; } =20 =20 int virSecretObjSaveData(virSecretObjPtr obj) { - char *base64 =3D NULL; - int ret =3D -1; + g_autofree char *base64 =3D NULL; =20 if (!obj->value) return 0; =20 if (!(base64 =3D virStringEncodeBase64(obj->value, obj->value_size))) - goto cleanup; + return -1; =20 if (virFileRewriteStr(obj->base64File, S_IRUSR | S_IWUSR, base64) < 0) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(base64); - return ret; + return 0; } =20 =20 @@ -762,7 +752,8 @@ virSecretObjSetValue(virSecretObjPtr obj, size_t value_size) { virSecretDefPtr def =3D obj->def; - unsigned char *old_value, *new_value; + g_autofree unsigned char *old_value =3D NULL; + g_autofree unsigned char *new_value =3D NULL; size_t old_value_size; =20 if (VIR_ALLOC_N(new_value, value_size) < 0) @@ -772,26 +763,24 @@ virSecretObjSetValue(virSecretObjPtr obj, old_value_size =3D obj->value_size; =20 memcpy(new_value, value, value_size); - obj->value =3D new_value; + obj->value =3D g_steal_pointer(&new_value); obj->value_size =3D value_size; =20 if (!def->isephemeral && virSecretObjSaveData(obj) < 0) goto error; =20 /* Saved successfully - drop old value */ - if (old_value) { + if (old_value) memset(old_value, 0, old_value_size); - VIR_FREE(old_value); - } =20 return 0; =20 error: /* Error - restore previous state and free new value */ - obj->value =3D old_value; + new_value =3D g_steal_pointer(&obj->value); + obj->value =3D g_steal_pointer(&old_value); obj->value_size =3D old_value_size; memset(new_value, 0, value_size); - VIR_FREE(new_value); return -1; } =20 @@ -835,7 +824,8 @@ virSecretLoadValue(virSecretObjPtr obj) { int ret =3D -1, fd =3D -1; struct stat st; - char *contents =3D NULL, *value =3D NULL; + g_autofree char *contents =3D NULL; + char *value =3D NULL; size_t value_size; =20 if ((fd =3D open(obj->base64File, O_RDONLY)) =3D=3D -1) { @@ -892,10 +882,8 @@ virSecretLoadValue(virSecretObjPtr obj) memset(value, 0, value_size); VIR_FREE(value); } - if (contents !=3D NULL) { + if (contents !=3D NULL) memset(contents, 0, st.st_size); - VIR_FREE(contents); - } VIR_FORCE_CLOSE(fd); return ret; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list