From nobody Sat Apr 20 01:38:26 2024 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=1568117092; cv=none; d=zoho.com; s=zohoarc; b=RNf9Duo42B+iALEwE8AvIFHFvm1TxvLtTZnChDkSkhrKJGPLH75jxME1d7yZCszEk+g9mRFxpLwwq39hzfobnpoZWCY5KfXefzGUCV3Qc30zqAl43zqH1wqygKOdU56GlhNWHgh/5KPNuhWqKKO3dmjGvFUvOsU/UOAF60a2070= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568117092; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=JbGUFW/p+HjKrXZACFiWD0kkDv9HEeLqwf4fSnlqp3s=; b=WzOi4nUDBHkmgCdivFHUvkjKOhNtBOx9BNFsa90wX/H/Hbvoari1NjG3lXl5gs0irDEx1NWEA4UMBNbGVEpLmMd0zvYZW59elMMnMSA05JJNwsulCZTKA3V7y0MmKiSSOv1MVcTOygzsrA2SFZ/0GN3freEDRGt5/WpfHM5ceUg= 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 1568117092983762.2188318976795; Tue, 10 Sep 2019 05:04:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AE231302455F; Tue, 10 Sep 2019 12:04:50 +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 256B160BE2; Tue, 10 Sep 2019 12:04:50 +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 F3CAF180221D; Tue, 10 Sep 2019 12:04:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8AC4lKe032661 for ; Tue, 10 Sep 2019 08:04:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 80F8D60BF3; Tue, 10 Sep 2019 12:04:47 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.188]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5639D60BE2 for ; Tue, 10 Sep 2019 12:04:45 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id C113910029F; Tue, 10 Sep 2019 14:04:43 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 10 Sep 2019 14:04:38 +0200 Message-Id: <47fdb058508709b3a9cac075715cafa18ea114b0.1568117078.git.jdenemar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] qemu: Don't leak domain def when RevertToSnapshot fails 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-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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 10 Sep 2019 12:04:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Once we copy the domain definition from virDomainSnapshotDef, we either need to assign it to the domain object or free it to avoid memory leaks. Signed-off-by: Jiri Denemark Reviewed-by: Pavel Hrdina --- src/qemu/qemu_driver.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index b28a26c3d6..a984b1e65c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -16568,6 +16568,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr sna= pshot, virCPUDefPtr origCPU =3D NULL; unsigned int start_flags =3D VIR_QEMU_PROCESS_START_GEN_VMID; qemuDomainAsyncJob jobType =3D QEMU_ASYNC_JOB_START; + bool defined =3D false; =20 virCheckFlags(VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING | VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED | @@ -16779,6 +16780,8 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr sna= pshot, virDomainObjAssignDef(vm, config, false, NULL); virCPUDefFree(priv->origCPU); VIR_STEAL_PTR(priv->origCPU, origCPU); + config =3D NULL; + defined =3D true; } =20 if (cookie && !cookie->slirpHelper) @@ -16788,8 +16791,11 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr sn= apshot, /* Transitions 2, 3 */ load: was_stopped =3D true; - if (config) + if (config) { virDomainObjAssignDef(vm, config, false, NULL); + config =3D NULL; + defined =3D true; + } =20 /* No cookie means libvirt which saved the domain was too old = to * mess up the CPU definitions. @@ -16875,8 +16881,11 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr sn= apshot, qemuProcessEndJob(driver, vm); goto cleanup; } - if (config) + if (config) { virDomainObjAssignDef(vm, config, false, NULL); + config =3D NULL; + defined =3D true; + } =20 if (flags & (VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING | VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)) { @@ -16944,7 +16953,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr sna= pshot, } else if (snap) { virDomainSnapshotSetCurrent(vm->snapshots, NULL); } - if (ret =3D=3D 0 && config && vm->persistent && + if (ret =3D=3D 0 && defined && vm->persistent && !(ret =3D virDomainSaveConfig(cfg->configDir, driver->caps, vm->newDef ? vm->newDef : vm->def))) { detail =3D VIR_DOMAIN_EVENT_DEFINED_FROM_SNAPSHOT; @@ -16960,6 +16969,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr sna= pshot, virObjectUnref(cfg); virNWFilterUnlockFilterUpdates(); virCPUDefFree(origCPU); + virDomainDefFree(config); =20 return ret; } --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list