From nobody Tue Dec 16 06:14:50 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; 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1528477833969720.2919437976053; Fri, 8 Jun 2018 10:10:33 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F133804F3; Fri, 8 Jun 2018 17:10:30 +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 004D55D9C7; Fri, 8 Jun 2018 17:10:28 +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 BD0E51800FC1; Fri, 8 Jun 2018 17:10:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w58HAOYE019657 for ; Fri, 8 Jun 2018 13:10:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 82A452010D0E; Fri, 8 Jun 2018 17:10:24 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-102.phx2.redhat.com [10.3.117.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 45B532010CA0 for ; Fri, 8 Jun 2018 17:10:24 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Jun 2018 13:10:15 -0400 Message-Id: <20180608171019.32167-3-jferlan@redhat.com> In-Reply-To: <20180608171019.32167-1-jferlan@redhat.com> References: <20180608171019.32167-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/6] vbox: Fix resource leak 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 08 Jun 2018 17:10:32 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The @disk was allocated, filled in, and consumed on the normal path, but for error/cleanup paths it would be leaked. Rename to newHardDisk and manage properly. Found by Coverity Signed-off-by: John Ferlan --- src/vbox/vbox_common.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 0e7fe06748..664650f217 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -4629,6 +4629,7 @@ vboxSnapshotRedefine(virDomainPtr dom, unsigned char snapshotUuid[VIR_UUID_BUFLEN]; virVBoxSnapshotConfHardDiskPtr *hardDiskToOpen =3D NULL; size_t hardDiskToOpenSize =3D 0; + virVBoxSnapshotConfHardDiskPtr newHardDisk =3D NULL; char **searchResultTab =3D NULL; ssize_t resultSize =3D 0; int it =3D 0; @@ -5236,7 +5237,6 @@ vboxSnapshotRedefine(virDomainPtr dom, PRUnichar *newLocation =3D NULL; char *newLocationUtf8 =3D NULL; resultCodeUnion resultCode; - virVBoxSnapshotConfHardDiskPtr disk =3D NULL; char *uuid =3D NULL; char *format =3D NULL; char *tmp =3D NULL; @@ -5301,11 +5301,11 @@ vboxSnapshotRedefine(virDomainPtr dom, } VBOX_RELEASE(progress); /* - * The differential disk is created, we add it to the media re= gistry and the - * machine storage controllers. + * The differential newHardDisk is created, we add it to the + * media registry and the machine storage controllers. */ =20 - if (VIR_ALLOC(disk) < 0) + if (VIR_ALLOC(newHardDisk) < 0) goto cleanup; =20 rc =3D gVBoxAPI.UIMedium.GetId(newMedium, &iid); @@ -5316,24 +5316,25 @@ vboxSnapshotRedefine(virDomainPtr dom, goto cleanup; } gVBoxAPI.UIID.vboxIIDToUtf8(data, &iid, &uuid); - disk->uuid =3D uuid; + newHardDisk->uuid =3D uuid; vboxIIDUnalloc(&iid); =20 - if (VIR_STRDUP(disk->location, newLocationUtf8) < 0) + if (VIR_STRDUP(newHardDisk->location, newLocationUtf8) < 0) goto cleanup; =20 rc =3D gVBoxAPI.UIMedium.GetFormat(newMedium, &formatUtf16); VBOX_UTF16_TO_UTF8(formatUtf16, &format); - disk->format =3D format; + newHardDisk->format =3D format; VBOX_UTF16_FREE(formatUtf16); =20 - if (virVBoxSnapshotConfAddHardDiskToMediaRegistry(disk, + if (virVBoxSnapshotConfAddHardDiskToMediaRegistry(newHardDisk, snapshotMachineDesc->mediaRegis= try, parentUuid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to add hard disk to the media reg= istry")); goto cleanup; } + newHardDisk =3D NULL; /* Consumed by above */ /*Adding the fake disk to the machine storage controllers*/ =20 resultSize =3D virStringSearch(snapshotMachineDesc->storageCon= troller, @@ -5348,7 +5349,7 @@ vboxSnapshotRedefine(virDomainPtr dom, =20 tmp =3D virStringReplace(snapshotMachineDesc->storageControlle= r, searchResultTab[it], - disk->uuid); + uuid); VIR_FREE(snapshotMachineDesc->storageController); if (!tmp) goto cleanup; @@ -5458,6 +5459,7 @@ vboxSnapshotRedefine(virDomainPtr dom, virStringListFree(realReadOnlyDisksPath); virStringListFree(realReadWriteDisksPath); virStringListFree(searchResultTab); + virVboxSnapshotConfHardDiskFree(newHardDisk); VIR_FREE(hardDiskToOpen); VIR_FREE(newSnapshotPtr); VIR_FREE(machineLocationPath); --=20 2.14.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list