From nobody Sun Feb 8 20:35:35 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1580673736536110.60376408788886; Sun, 2 Feb 2020 12:02:16 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-225-RoaLndWtM0qx_5w7dsBhcQ-1; Sun, 02 Feb 2020 15:02:11 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6B7BD105046A; Sun, 2 Feb 2020 20:02:05 +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 3FD825C3FD; Sun, 2 Feb 2020 20:02:05 +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 E264018089CE; Sun, 2 Feb 2020 20:02:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 012K1rX9003424 for ; Sun, 2 Feb 2020 15:01:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id BEAA85D9E5; Sun, 2 Feb 2020 20:01:53 +0000 (UTC) Received: from icr.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DD7C5D9CA for ; Sun, 2 Feb 2020 20:01:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580673735; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=kiO2Gi5CR7BRoPEJXpK+4xqkVPZIJuTrQyd5zKUbDfE=; b=BXF5HTS7jH5iGy29XbMXV8apUDxI77HDp9ShyWgXKKIHsZwdwrYkDF6GuAVh2llzDBeqnt 90ui3/RakTcl5cV+Plead5A+AI6XXaHxFhuVoEwirDS6ukGB4TSo1ASsP5vrulVpP594KW i/rGGhqKKUQKaeEfVqm6KXJP2igFxJI= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 2/4] qemu: tpm: use g_autofree Date: Sun, 2 Feb 2020 21:01:45 +0100 Message-Id: <67dbb235284237f6c56d5cf2cbe1eeb5c43ab7a6.1580673678.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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: , 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-MC-Unique: RoaLndWtM0qx_5w7dsBhcQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Mark eligible declarations as g_autofree and remove the corresponding VIR_FREE calls. Signed-off-by: J=C3=A1n Tomko --- src/qemu/qemu_tpm.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index 385f4c74f7..cfe7eb1846 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -126,7 +126,7 @@ qemuTPMCreateEmulatorStorage(const char *storagepath, gid_t swtpm_group) { int ret =3D -1; - char *swtpmStorageDir =3D g_path_get_dirname(storagepath); + g_autofree char *swtpmStorageDir =3D g_path_get_dirname(storagepath); =20 if (qemuTPMEmulatorInitStorage(swtpmStorageDir) < 0) goto cleanup; @@ -150,8 +150,6 @@ qemuTPMCreateEmulatorStorage(const char *storagepath, ret =3D 0; =20 cleanup: - VIR_FREE(swtpmStorageDir); - return ret; } =20 @@ -220,14 +218,12 @@ qemuTPMEmulatorCreatePidFilename(const char *swtpmSta= teDir, const char *shortName) { char *pidfile =3D NULL; - char *devicename =3D NULL; + g_autofree char *devicename =3D NULL; =20 devicename =3D g_strdup_printf("%s-swtpm", shortName); =20 pidfile =3D virPidFileBuildPath(swtpmStateDir, devicename); =20 - VIR_FREE(devicename); - return pidfile; } =20 @@ -433,7 +429,7 @@ qemuTPMEmulatorRunSetup(const char *storagepath, int exitstatus; int ret =3D -1; char uuid[VIR_UUID_STRING_BUFLEN]; - char *vmid =3D NULL; + g_autofree char *vmid =3D NULL; g_autofree char *swtpm_setup =3D virTPMGetSwtpmSetup(); VIR_AUTOCLOSE pwdfile_fd =3D -1; =20 @@ -516,7 +512,6 @@ qemuTPMEmulatorRunSetup(const char *storagepath, ret =3D 0; =20 cleanup: - VIR_FREE(vmid); virCommandFree(cmd); =20 return ret; @@ -554,7 +549,7 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDefPtr tpm, { virCommandPtr cmd =3D NULL; bool created =3D false; - char *pidfile; + g_autofree char *pidfile =3D NULL; g_autofree char *swtpm =3D virTPMGetSwtpm(); VIR_AUTOCLOSE pwdfile_fd =3D -1; VIR_AUTOCLOSE migpwdfile_fd =3D -1; @@ -615,7 +610,6 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDefPtr tpm, =20 virCommandAddArg(cmd, "--pid"); virCommandAddArgFormat(cmd, "file=3D%s", pidfile); - VIR_FREE(pidfile); =20 if (tpm->data.emulator.hassecretuuid) { if (!virTPMSwtpmCapsGet(VIR_TPM_SWTPM_FEATURE_CMDARG_PWD_FD)) { @@ -669,8 +663,8 @@ qemuTPMEmulatorStop(const char *swtpmStateDir, const char *shortName) { virCommandPtr cmd; - char *pathname; - char *errbuf =3D NULL; + g_autofree char *pathname =3D NULL; + g_autofree char *errbuf =3D NULL; g_autofree char *swtpm_ioctl =3D virTPMGetSwtpmIoctl(); =20 if (!swtpm_ioctl) @@ -701,8 +695,7 @@ qemuTPMEmulatorStop(const char *swtpmStateDir, unlink(pathname); =20 cleanup: - VIR_FREE(pathname); - VIR_FREE(errbuf); + return; } =20 =20 @@ -735,7 +728,7 @@ qemuExtTPMPrepareHost(virQEMUDriverPtr driver, { virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); int ret =3D 0; - char *shortName =3D NULL; + g_autofree char *shortName =3D NULL; =20 switch (def->tpm->type) { case VIR_DOMAIN_TPM_TYPE_EMULATOR: @@ -755,7 +748,6 @@ qemuExtTPMPrepareHost(virQEMUDriverPtr driver, } =20 cleanup: - VIR_FREE(shortName); virObjectUnref(cfg); =20 return ret; @@ -885,7 +877,7 @@ qemuExtTPMStop(virQEMUDriverPtr driver, virDomainObjPtr vm) { virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); - char *shortName =3D NULL; + g_autofree char *shortName =3D NULL; =20 switch (vm->def->tpm->type) { case VIR_DOMAIN_TPM_TYPE_EMULATOR: @@ -902,7 +894,6 @@ qemuExtTPMStop(virQEMUDriverPtr driver, } =20 cleanup: - VIR_FREE(shortName); virObjectUnref(cfg); } =20 @@ -913,7 +904,7 @@ qemuExtTPMSetupCgroup(virQEMUDriverPtr driver, virCgroupPtr cgroup) { virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); - char *shortName =3D NULL; + g_autofree char *shortName =3D NULL; int ret =3D -1, rc; pid_t pid; =20 @@ -939,7 +930,6 @@ qemuExtTPMSetupCgroup(virQEMUDriverPtr driver, ret =3D 0; =20 cleanup: - VIR_FREE(shortName); virObjectUnref(cfg); =20 return ret; --=20 2.19.2