From nobody Sun Oct 5 01:49:25 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1757491681; cv=none; d=zohomail.com; s=zohoarc; b=Pibc3X5ECBKgxmOXH9IbYRn76HYErM2wtpaMeFd+ocgtbOAQuE/jQBGEazCPrDiNiDv5wJ6O+z/txVE7iR6eLy1OPvHEw629FF7YPyrAHHnvhDZd9BKnfl1Dk1mReES8PNre6viWT9/u3eZnl80ou4/emV6GJIQVHvEhpbNv45c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757491681; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=lJ23vWp3eSF5IOEXAuIF0H+vtdcr3V8HjvHx94b1Ew8=; b=ScZbZutY/t1hUJklNcLCrPDkmFHmPrRtWKfPLeGIA61aC5CLkJ9yrHv8XwpGqMg0uIaHuxeUUVjwj+ZjqGbMIgpC8OGmk9dhSuCSPAKeoa4DXqbQ3ZPWYrrI3xRUouDRW6iMg1NYTdQSiQZ9HV6imHCCYDHm0yj+JaRE4SwRNAk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1757491681419340.9226636274318; Wed, 10 Sep 2025 01:08:01 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id CF45341B73; Wed, 10 Sep 2025 04:07:53 -0400 (EDT) Received: from [172.19.199.3] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 056D643DF4; Wed, 10 Sep 2025 04:05:19 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 06CCF41A9A; Wed, 10 Sep 2025 04:03:53 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id F37C541AFC for ; Wed, 10 Sep 2025 04:03:52 -0400 (EDT) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-328-JLAO3E-YP9m2bIK-yrJf9g-1; Wed, 10 Sep 2025 04:03:51 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A405C1800562 for ; Wed, 10 Sep 2025 08:03:50 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0A50D19560AB for ; Wed, 10 Sep 2025 08:03:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757491432; h=from:from: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; bh=lJ23vWp3eSF5IOEXAuIF0H+vtdcr3V8HjvHx94b1Ew8=; b=ifr6BQ7MZbCAxiwCogP69BC4PtFLy6J5AGYaXg5CEhS/MAYswdkIeaywfGuD7FFNiUR8XH /lpmjU+4DebZ/AXMoZjTUJQ8fGBTevSpq2MYWHW8gwm3Y+tc6Rd7cSQ9hWNzNoqveksf5I weevcsSPlQCf5aJJe6Q5TXF847Zkrmk= X-MC-Unique: JLAO3E-YP9m2bIK-yrJf9g-1 X-Mimecast-MFC-AGG-ID: JLAO3E-YP9m2bIK-yrJf9g_1757491430 To: devel@lists.libvirt.org Subject: [PATCH 4/4] ch: Avoid memleak on disk detach in chDomainRemoveDevice() Date: Wed, 10 Sep 2025 10:03:41 +0200 Message-ID: <51bc73f7d4bf7c028033fb21035e85c5278a0204.1757491293.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: GACcbMb3ep-m3GHyiZ6_fpXiMoo4h5WRA-lvPg4lcg8_1757491430 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: SABW6Z3BDB4TTMZACKPLBKNOASLQJM3B X-Message-ID-Hash: SABW6Z3BDB4TTMZACKPLBKNOASLQJM3B X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1757491684746154100 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik The aim of chDomainRemoveDevice() is to remove device from virDomainDef. Well, in case of disks this is done by calling virDomainDiskRemove() which merely just removes it from the array of virDomainDiskDef-s but leaves it up to the caller to actually free the disk def. 1,286 (560 direct, 726 indirect) bytes in 1 blocks are definitely lost in l= oss record 2,005 of 2,041 at 0x4919EF3: calloc (vg_replace_malloc.c:1675) by 0x4FEB249: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.8400.3) by 0x4AFD9A4: virDomainDiskDefNewSource (domain_conf.c:2409) by 0x4B10ACA: virDomainDiskDefParseXML (domain_conf.c:8509) by 0x4B24F07: virDomainDeviceDefParse (domain_conf.c:14631) by 0xB8D8881: chDomainAttachDeviceLiveAndUpdateConfig (ch_hotplug.c:135) by 0xB8CCFE0: chDomainAttachDeviceFlags (ch_driver.c:2376) by 0xB8CD057: chDomainAttachDevice (ch_driver.c:2394) by 0x4DC1C7D: virDomainAttachDevice (libvirt-domain.c:8951) by 0x405E545: remoteDispatchDomainAttachDevice (remote_daemon_dispatch_s= tubs.h:3763) by 0x405E495: remoteDispatchDomainAttachDeviceHelper (remote_daemon_disp= atch_stubs.h:3742) by 0x4BF3164: virNetServerProgramDispatchCall (virnetserverprogram.c:423) Signed-off-by: Michal Privoznik --- src/ch/ch_hotplug.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ch/ch_hotplug.c b/src/ch/ch_hotplug.c index cfa11cc5e5..0a55a57069 100644 --- a/src/ch/ch_hotplug.c +++ b/src/ch/ch_hotplug.c @@ -212,6 +212,7 @@ chDomainRemoveDevice(virDomainObj *vm, for (i =3D 0; i < vm->def->ndisks; i++) { if (vm->def->disks[i] =3D=3D device->data.disk) { virDomainDiskRemove(vm->def, i); + g_clear_pointer(&device->data.disk, virDomainDiskDefFree); break; } } --=20 2.49.1