From nobody Mon Feb 9 03:20:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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=1667231599; cv=none; d=zohomail.com; s=zohoarc; b=IyR1oMq2XaqZXhuw88DbwCmrZK80E/L4yQVI91w4m2FrzUgNd91Qx7Nur90klc/pzZnrZoG+bzUVn2ipOZx3m4F1y416zC34w8GWQIYiLeat43hXmvuZRlY92CuxJFyYTSEoJqP4iLxSV2qWtPczdDpiQTkC/6d5UloPR9/9XV8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667231599; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rxZAzNviVJHI52Q2EhBA2pRNcaz03D5SK7/Sa/RS/pI=; b=I1AGqqXl69f/7ELbunkuCV/0RNxG+t5AuL6qmxQAX6sQq+Eur2RQUuiQ5bhnzJSOpC5JK0kneB4FgWxSGDzQmstI3eZdY0jZXVKPHh58ddqhN0siI8ATCWAbsnShPgSkL8UhXbvccF6eVUmeJf6wUBiwHXCMrhNgkQBILfjOt9U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1667231599228221.3760032424351; Mon, 31 Oct 2022 08:53:19 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-544-zTn0zPchNAK_cV1iwCs4bg-1; Mon, 31 Oct 2022 11:53:14 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2DCC486C058; Mon, 31 Oct 2022 15:53:12 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9632F1401C23; Mon, 31 Oct 2022 15:53:11 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 70ABA1946A44; Mon, 31 Oct 2022 15:53:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A7BA01946594 for ; Mon, 31 Oct 2022 15:53:03 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 39D9940C6FA1; Mon, 31 Oct 2022 15:53:03 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id D385B40C6EC6 for ; Mon, 31 Oct 2022 15:53:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667231598; 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=rxZAzNviVJHI52Q2EhBA2pRNcaz03D5SK7/Sa/RS/pI=; b=IO5A25oLtU7xl+W1VqoPU7Aivskd+NI/5gHxTq+K0uPe33TiWCbriAK3q4xNH6SltLYUV+ qVXdR+EBU5NcVsHMvmGSGK2IVVP/Ox9RX6thG4+kxfrCtoULefC/ku8t2NtSaaodTqi2rX 1kivlYC4d7oNWaDj8YKWObEcbmwSvW4= X-MC-Unique: zTn0zPchNAK_cV1iwCs4bg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/2] qemu_namespace: Don't leak memory in qemuDomainGetPreservedMounts() Date: Mon, 31 Oct 2022 16:52:59 +0100 Message-Id: <17283b3497fb4fa497562ba21f1e1139cf8ed978.1667231427.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1667231600224100001 Content-Type: text/plain; charset="utf-8"; x-default="true" The aim of qemuDomainGetPreservedMounts() is to get a list of filesystems mounted under /dev and optionally generate a path for each one where they are moved temporarily when building the namespace. And the function tries to be a bit clever about it. For instance, if /dev/shm mount point exists, there's no need to consider /dev/shm/a nor /dev/shm/b as preserving just 'top level' /dev/shm gives the same result. To achieve this, the function iterates over the list of filesystem as returned by virFileGetMountSubtree() and removes the nested ones. However, it does so in a bit clumsy way: plain VIR_DELETE_ELEMENT() is used without freeing the string itself. Therefore, if all three aforementioned example paths appeared on the list, /dev/shm/a and /dev/shm/b strings would be leaked. And when I think about it more, there's no real need to shrink the array down (realloc()). It's going to be free()-d when returning from the function. Switch to VIR_DELETE_ELEMENT_INPLACE() then. Fixes: cdd9205dfffa3aaed935446a41f0d2dd1357c268 Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko Reviewed-by: Peter Krempa --- src/qemu/qemu_namespace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index 311c66d46e..9fed6871e8 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -159,7 +159,8 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfig *cfg, =20 if (c && (*c =3D=3D '/' || *c =3D=3D '\0')) { VIR_DEBUG("Dropping path %s because of %s", mounts[j], mou= nts[i]); - VIR_DELETE_ELEMENT(mounts, j, nmounts); + VIR_FREE(mounts[j]); + VIR_DELETE_ELEMENT_INPLACE(mounts, j, nmounts); } else { j++; } --=20 2.37.4