]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_tpm.c: fix 'shortName' leak
authorDaniel Henrique Barboza <danielhb413@gmail.com>
Sat, 14 Nov 2020 12:56:41 +0000 (09:56 -0300)
committerDaniel Henrique Barboza <danielhb413@gmail.com>
Mon, 16 Nov 2020 16:55:06 +0000 (13:55 -0300)
This is a Coverity fix pointed out by John in IRC. This code
was introduced in 19d74fdf0eb, when the TPM Proxy device for
for ppc64 was introduced.

This will leak in case we have 2 TPMs in the same domain, a
possible scenario with the protected Ultravisor execution in
PowerPC guests.

Fixes: 19d74fdf0eb5d2e89e80ceedea736425160ffccb
Reported-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/qemu/qemu_tpm.c

index 8adb0e42b839b8567388b6bf4cf677c351adb3e2..872be165704ee27c337a4e5f534e223ba7f637dd 100644 (file)
@@ -841,10 +841,11 @@ qemuExtTPMStop(virQEMUDriverPtr driver,
                virDomainObjPtr vm)
 {
     g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
-    g_autofree char *shortName = NULL;
     size_t i;
 
     for (i = 0; i < vm->def->ntpms; i++) {
+        g_autofree char *shortName = NULL;
+
         if (vm->def->tpms[i]->type != VIR_DOMAIN_TPM_TYPE_EMULATOR)
             continue;
 
@@ -866,12 +867,13 @@ qemuExtTPMSetupCgroup(virQEMUDriverPtr driver,
                       virCgroupPtr cgroup)
 {
     g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
-    g_autofree char *shortName = NULL;
     int rc;
     pid_t pid;
     size_t i;
 
     for (i = 0; i < def->ntpms; i++) {
+        g_autofree char *shortName = NULL;
+
         if (def->tpms[i]->type != VIR_DOMAIN_TPM_TYPE_EMULATOR)
             continue;