From nobody Sun Dec 22 03:04:26 2024 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1734535908888997.7902260526565; Wed, 18 Dec 2024 07:31:48 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id D6B1F15D3; Wed, 18 Dec 2024 10:31:47 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 2DC8415C4; Wed, 18 Dec 2024 10:31:31 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 87B2415B6; Wed, 18 Dec 2024 10:31:27 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 9D30115AA for ; Wed, 18 Dec 2024 10:31:26 -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-237-lu4qNOE-MKmd8gQNlErn3g-1; Wed, 18 Dec 2024 10:31:24 -0500 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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1C7881955F56 for ; Wed, 18 Dec 2024 15:31:24 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.3.236]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 61C40195394B for ; Wed, 18 Dec 2024 15:31:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734535886; 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; bh=qhXWSDzW7tMyujFpSwML0Bu53lxZJHRkMMYDgRfav2o=; b=O/KRaPK5ccIwHfNDsUJKfWLAbAUAFVeHGgUmRWZplPsE5TaZh8wiAKsX81BbpuOhSrFdv5 A4mVVtbdr40Vgt+9DqgoOXsPFTUj56alfD3xoKJy2XpwMixiTNQo3I1ZkR69VK+iD1Skgf 0CMl7qIFpJ+W3IEymLPjbs12HJG/hlU= X-MC-Unique: lu4qNOE-MKmd8gQNlErn3g-1 X-Mimecast-MFC-AGG-ID: lu4qNOE-MKmd8gQNlErn3g From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH] qemu_capabilities: Avoid memleak in virQEMUCapsProbeFullDeprecatedProperties() Date: Wed, 18 Dec 2024 16:31:20 +0100 Message-ID: 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: JgvBE1ZjsECEqr8s6ZomIqxNpzyO8L9O_pgfNwYjlaI_1734535884 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: WQO5UPILIBBMNECWP7WTKQNRGG7VOF6Z X-Message-ID-Hash: WQO5UPILIBBMNECWP7WTKQNRGG7VOF6Z X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1734535910858116600 Content-Type: text/plain; charset="utf-8"; x-default="true" As one of its arguments, the virQEMUCapsProbeFullDeprecatedProperties() gets a pointer to GStrv (a string list), which it may eventually replace. It's single caller (virQEMUCapsProbeQMPHostCPU()) passes a string list indeed. Now, when replacing one string list with another plain g_free() is not enough as we need to free individual strings too. =3D=3D13573=3D=3D 34 bytes in 8 blocks are definitely lost in loss record 2= 71 of 576 =3D=3D13573=3D=3D at 0x4844878: malloc (vg_replace_malloc.c:446) =3D=3D13573=3D=3D by 0x51789D1: g_malloc (in /usr/lib64/libglib-2.0.so.0= .7800.6) =3D=3D13573=3D=3D by 0x5193E82: g_strdup (in /usr/lib64/libglib-2.0.so.0= .7800.6) =3D=3D13573=3D=3D by 0x4997F73: g_strdup_inline (gstrfuncs.h:321) =3D=3D13573=3D=3D by 0x4997F73: virJSONValueArrayToStringList (virjson.c= :1296) =3D=3D13573=3D=3D by 0x5027CF7: qemuMonitorJSONParseCPUModelExpansion (q= emu_monitor_json.c:5139) =3D=3D13573=3D=3D by 0x50281C9: qemuMonitorJSONGetCPUModelExpansion (qem= u_monitor_json.c:5245) =3D=3D13573=3D=3D by 0x501044F: qemuMonitorGetCPUModelExpansion (qemu_mo= nitor.c:3261) =3D=3D13573=3D=3D by 0x4F190D0: virQEMUCapsProbeQMPHostCPU (qemu_capabil= ities.c:3227) =3D=3D13573=3D=3D by 0x4F2145E: virQEMUCapsInitQMPMonitor (qemu_capabili= ties.c:5758) =3D=3D13573=3D=3D by 0x10FFF8: testQemuCaps (qemucapabilitiestest.c:111) =3D=3D13573=3D=3D by 0x110B53: virTestRun (testutils.c:143) =3D=3D13573=3D=3D by 0x11063E: doCapsTest (qemucapabilitiestest.c:200) Fixes: 51c098347d7f2af9b4386ac0adc4431997d06f3d Signed-off-by: Michal Privoznik Reviewed-by: Boris Fiuczynski --- src/qemu/qemu_capabilities.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index eda3e6a4df..27a283cff6 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -3176,7 +3176,7 @@ virQEMUCapsProbeFullDeprecatedProperties(qemuMonitor = *mon, return -1; =20 if (propsInfo && propsInfo->deprecated_props) { - g_free(*props); + g_strfreev(*props); *props =3D g_steal_pointer(&propsInfo->deprecated_props); } =20 --=20 2.45.2