From nobody Tue Feb 10 03:44:47 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=1689776026; cv=none; d=zohomail.com; s=zohoarc; b=mlYVQ7ha4KHYlnru8cwUZJpVxJExYZwcUcXIp+Ru83H33WDBHpHLM6L94w0uqhQPNOfiX0CqS+OLZmHQEVI2SkSnHbqJZIFxmIB46w11bG7Hmt2kgwkfM36QJBbwAkDXnbFGY08nBW2EKXmFpFwmlQjd6C6qbE/hWKyaKwzU6ws= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689776026; 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; bh=kVAhQcavDuWZgZfecl+92rYIiH6aBodDURa7W6u/DaM=; b=nq9zx4T2f3BtsYMOt6n5gsiqptH8hPuDl/RnKDzm9cnWZ/zaJqRpDt262EjBxjquwoN6ZvHsnBGM4ckhVZNElO5ugmXLDfLE9fDAs7ONgJvF+iNXuG9Lwj0KYbp02Ih5ZArHx2I7meWqDEVRaPIqNbEfHWYuwzPI7EhVAFPURIo= 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 1689776026463137.69709031603657; Wed, 19 Jul 2023 07:13:46 -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-558-SvGd9TiiP3usMLYbmf3bJw-1; Wed, 19 Jul 2023 10:13:39 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B8C7B887119; Wed, 19 Jul 2023 14:13:19 +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 9D78C2166B25; Wed, 19 Jul 2023 14:13:19 +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 442A51946597; Wed, 19 Jul 2023 14:13:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3A4651946589 for ; Wed, 19 Jul 2023 13:41:20 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 6FC332166B27; Wed, 19 Jul 2023 13:41:20 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7109C2166B25 for ; Wed, 19 Jul 2023 13:41:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689776025; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=kVAhQcavDuWZgZfecl+92rYIiH6aBodDURa7W6u/DaM=; b=JXdWbrYz18ghIln4NGRdLQiE+qrjuLpNTiep/dfxud12O8RbXoRN8sNldLXOWlyMKYczmZ ZEv5DvM1RIGyu+1eOvDLCQAun6Xct1dzYtta/NXr+1OWB7JiazMPB//XxRr3LcFU6r74bv qmUz2RWBa101bbWxoOsiCnCbhmN51I4= X-MC-Unique: SvGd9TiiP3usMLYbmf3bJw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH] node_device: Don't leak error message buffer from virMdevctlListDefined|Active Date: Wed, 19 Jul 2023 15:41:17 +0200 Message-ID: <24c2a4a3e69cc60e96e14e1ac95fdd320c41f561.1689774077.git.pkrempa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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.6 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: 1689776028551100001 Content-Type: text/plain; charset="utf-8" nodeDeviceUpdateMediatedDevices invokes virMdevctlListDefined and virMdevctlListActive both of which were passed the same 'errmsg' buffer. Since virCommandSetErrorBuffer() always allocates the error buffer one of them was leaked. Fix it by populating the 'errmsg' buffer only on failure of virMdevctlListActive|Defined which invoke the command. Add a comment to nodeDeviceGetMdevctlListCommand reminding how virCommandSetErrorBuffer() works. Fixes: 44a0f2f0c8f Signed-off-by: Peter Krempa Reviewed-by: Boris Fiuczynski --- src/node_device/node_device_driver.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index a2d0600560..f8fae71194 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1044,6 +1044,15 @@ virMdevctlSetAutostart(virNodeDeviceDef *def, bool a= utostart, char **errmsg) } +/** + * nodeDeviceGetMdevctlListCommand: + * @defined: list mdevctl entries with persistent config + * @output: filled with the output of mdevctl once invoked + * @errmsg: always allocated, optionally filled with error from 'mdevctl' + * + * Prepares a virCommand structure to invoke 'mdevctl' caller is responsib= le to + * free the buffers which are filled by the virCommand infrastructure. + */ virCommand* nodeDeviceGetMdevctlListCommand(bool defined, char **output, @@ -1623,9 +1632,11 @@ virMdevctlListDefined(virNodeDeviceDef ***devs, char= **errmsg) { int status; g_autofree char *output =3D NULL; - g_autoptr(virCommand) cmd =3D nodeDeviceGetMdevctlListCommand(true, &o= utput, errmsg); + g_autofree char *errbuf =3D NULL; + g_autoptr(virCommand) cmd =3D nodeDeviceGetMdevctlListCommand(true, &o= utput, &errbuf); if (virCommandRun(cmd, &status) < 0 || status !=3D 0) { + *errmsg =3D g_steal_pointer(&errbuf); return -1; } @@ -1641,9 +1652,11 @@ virMdevctlListActive(virNodeDeviceDef ***devs, char = **errmsg) { int status; g_autofree char *output =3D NULL; - g_autoptr(virCommand) cmd =3D nodeDeviceGetMdevctlListCommand(false, &= output, errmsg); + g_autofree char *errbuf =3D NULL; + g_autoptr(virCommand) cmd =3D nodeDeviceGetMdevctlListCommand(false, &= output, &errbuf); if (virCommandRun(cmd, &status) < 0 || status !=3D 0) { + *errmsg =3D g_steal_pointer(&errbuf); return -1; } --=20 2.41.0