From nobody Sun Feb 8 21:29:08 2026 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=1770133461; cv=none; d=zohomail.com; s=zohoarc; b=i3S/RLbE0Jy5BkLVQKPDdl5ESs95Fu3AvydxSuCIUnMYj+ATdaJD2xzQl+R/G01CYAeV+p1woj1EyWVEyrTDFhq0tKZYHOVrS0Hn3gt1NIEK9IRKjfBFoBJD3rmg9mZkzG9PmJRDOhORyCk7S2/xX8U8wXgOoRV5FNh8RVsWQ6Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770133461; 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=b/Wmclbnqq9MhBIlMhhZMmx+X5ANK2vnlU9vipQBUaQ=; b=ftegurvL/AhbQgoBVkBk8htXRqcyyZsX0kH4kh9wrv+R/YuwZ++jJ7VJFPhb5p8io95mwzKXniduooqaO4041FHb/sUVtENRntP8TO/CITt8+29uZuMrU0FB+UAzFBX1iojTEhoRxwY1XiNP2orRiw60k4Wzr1oEsmCss/5mg7s= 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 177013346186193.6345732224064; Tue, 3 Feb 2026 07:44:21 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 16E4841C4B; Tue, 3 Feb 2026 10:44:21 -0500 (EST) Received: from [172.19.199.6] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 4F48643E98; Tue, 3 Feb 2026 10:40:26 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 7C19C41B74; Tue, 3 Feb 2026 10:40:21 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 C313641A97 for ; Tue, 3 Feb 2026 10:40:07 -0500 (EST) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-689-lF8mFkp-NbSv0qkqnSjreg-1; Tue, 03 Feb 2026 10:40:05 -0500 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 392AA19560B6 for ; Tue, 3 Feb 2026 15:40:04 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 95BFB1956048 for ; Tue, 3 Feb 2026 15:40:03 +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=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, 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=1770133207; 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=b/Wmclbnqq9MhBIlMhhZMmx+X5ANK2vnlU9vipQBUaQ=; b=TH/vt6yxn8jVKnmyH6kmVTU9KwytIFfmcojF0SY9zIEoWGRt8OGY5ZBJX1XUBkzpHerBP8 ar2uw/HosdVO6J3V9sosH2n+FD8IdKVbmdPCxvLUEuELZ1LcCdjCxU0qXq54pf1E0wcq1P xupwVZXQtVP9NuCtDaG5e/J+VEdGqxk= X-MC-Unique: lF8mFkp-NbSv0qkqnSjreg-1 X-Mimecast-MFC-AGG-ID: lF8mFkp-NbSv0qkqnSjreg_1770133204 To: devel@lists.libvirt.org Subject: [PATCH 3/9] bhyve_command: Avoid leaking @buf in virBhyveProcessBuildBhyveCmd() Date: Tue, 3 Feb 2026 16:39:51 +0100 Message-ID: <6668c0bcae325269149da90df9b2a12a01359bf4.1770133151.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: GyXhDpNKzXMuIRlBnQKUD444ihJwiPqZNhE1Ih4d_90_1770133204 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 37TMROBTVYYBDWR67NKPLC3MLNHZWXBT X-Message-ID-Hash: 37TMROBTVYYBDWR67NKPLC3MLNHZWXBT 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: 1770133463517158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik When building OS loader part of bhyve command line, there's @buf declared and it is even correctly annotated with g_auto() to be freed automatically. But then, the buffer contents is appended onto the command line using virBufferContentAndReset() which leads to a memleak because the buffer is reset. It's virBufferCurrentContent() that should have been used instead. 128 bytes in 1 blocks are definitely lost in loss record 476 of 536 at 0x48882B1: realloc (vg_replace_malloc.c:1810) by 0x4EE6622: g_realloc (in /usr/local/lib/libglib-2.0.so.0.8400.4) by 0x4F048BC: g_string_new (in /usr/local/lib/libglib-2.0.so.0.8400.4) by 0x4A59E1E: virBufferInitialize (virbuffer.c:121) by 0x4A5A63C: virBufferVasprintf (virbuffer.c:321) by 0x4A5A5DE: virBufferAsprintf (virbuffer.c:303) by 0x401B22F: virBhyveProcessBuildBhyveCmd (bhyve_command.c:1021) by 0x4015F05: testCompareXMLToArgvFiles (bhyvexml2argvtest.c:72) by 0x4015BA9: testCompareXMLToArgvHelper (bhyvexml2argvtest.c:144) by 0x4016588: virTestRun (testutils.c:143) by 0x4015919: mymain (bhyvexml2argvtest.c:341) by 0x4018882: virTestMain (testutils.c:913) Signed-off-by: Michal Privoznik --- src/bhyve/bhyve_command.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index a45a5d1c33..c9bfe22c8c 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -1003,7 +1003,7 @@ virBhyveProcessBuildBhyveCmd(struct _bhyveConn *drive= r, virDomainDef *def, if (def->os.bootloader =3D=3D NULL && def->os.loader) { virArch arch =3D def->os.arch; - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; =20 if (ARCH_IS_X86(arch)) { if ((bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_LPC_BOOTROM))= { @@ -1011,7 +1011,7 @@ virBhyveProcessBuildBhyveCmd(struct _bhyveConn *drive= r, virDomainDef *def, if (def->os.loader->nvram && def->os.loader->nvram->path) virBufferAsprintf(&buf, ",%s", def->os.loader->nvram->= path); =20 - virCommandAddArgList(cmd, "-l", virBufferContentAndReset(&= buf), NULL); + virCommandAddArgList(cmd, "-l", virBufferCurrentContent(&b= uf), NULL); } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Installed bhyve binary does not support = UEFI loader")); @@ -1019,7 +1019,7 @@ virBhyveProcessBuildBhyveCmd(struct _bhyveConn *drive= r, virDomainDef *def, } } else if (ARCH_IS_ARM(arch)) { virBufferAsprintf(&buf, "bootrom=3D%s", def->os.loader->path); - virCommandAddArgList(cmd, "-o", virBufferContentAndReset(&buf)= , NULL); + virCommandAddArgList(cmd, "-o", virBufferCurrentContent(&buf),= NULL); } } =20 --=20 2.52.0