From nobody Mon Apr 29 05:02:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1665409192; cv=none; d=zohomail.com; s=zohoarc; b=V1zVlFAEp92jOlb+AD3wNhTSGlPvqdY07dbTqeqow1g16etVC4HcrPxkUhWR3LiK5CC/9nA94Kj8gHfVcPn9VjviZD0QDItFioFii3ii6M20s6bfsrZtp34+TrBWc+Jon1nP4TzfMSQViLloqZ1JeGgXyzk2DwqIn/5IpgceIWY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665409192; 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=0y8gRJ0+MeOnd4hP58MX2YrpCsfPNdSV7yZR+4JTjLs=; b=TM7w7abEc1iTGn46Bjmc9wBcsX21T/G6drBe3FZvixb35bKdzsja3fTtF9ifE1j+gsXXnH33qEYHtVVVla+cPGQgAbn76rnN2tFDELy8qxiMTJUQVxgJQ61tqy0Nw3OvZle28BOSmsQNMvBcZ78GMrObZ67clD83TVyrFkH5Iz4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 166540919287881.38399652047792; Mon, 10 Oct 2022 06:39:52 -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-589-SavnlzHsPCWZRzRpTGScvw-1; Mon, 10 Oct 2022 09:39:45 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 18B09811E67; Mon, 10 Oct 2022 13:39:43 +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 1175F53592D; Mon, 10 Oct 2022 13:39:40 +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 E9F2F19465A0; Mon, 10 Oct 2022 13:39:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A14B31946597 for ; Mon, 10 Oct 2022 13:39:38 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 937AE53592D; Mon, 10 Oct 2022 13:39:38 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3993A40F156 for ; Mon, 10 Oct 2022 13:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665409191; 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=0y8gRJ0+MeOnd4hP58MX2YrpCsfPNdSV7yZR+4JTjLs=; b=jCZRFlTQz5qo+F0MuZqGXmj6YDrtEwhUh1hIZ5G8/ySMOv1+UymSlz/dyAYGf/2A7LIEgu XcHkZAxmhxVqKSbhaPm8+RO1XTaZwKsFcJGYQvLiBeW3Ig4TgcgFqVE1q6JWldOyOFxCSF pMqseTOAg8GzwVgAEabMRc8oadBF6nY= X-MC-Unique: SavnlzHsPCWZRzRpTGScvw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] qemu: Avoid memory leak in virQEMUCapsCPUDefsToModels Date: Mon, 10 Oct 2022 15:39:35 +0200 Message-Id: <48173a5de02bdf70a45cd13753f62a4a1f5769c9.1665409175.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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.10 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: 1665409193367100001 Content-Type: text/plain; charset="utf-8"; x-default="true" The @vendor variable inside virQEMUCapsCPUDefsToModels() is allocated, but never freed. But there is actually no need for it to be allocated, because it merely passes a retval of virCPUGetVendorForModel() (which returns a const string) to virDomainCapsCPUModelsAdd() (which ten accepts the argument as const string). Therefore, drop the g_strdup() call and fix the type of the variable. Signed-off-by: Michal Privoznik Reviewed-by: Jiri Denemark --- src/qemu/qemu_capabilities.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 6f3ff7f43f..04b2eef215 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2189,7 +2189,7 @@ virQEMUCapsCPUDefsToModels(virArch arch, =20 for (i =3D 0; i < defs->ncpus; i++) { qemuMonitorCPUDefInfo *cpu =3D defs->cpus + i; - char *vendor =3D NULL; + const char *vendor =3D NULL; =20 if (modelAllowed && !g_strv_contains(modelAllowed, cpu->name)) continue; @@ -2198,7 +2198,7 @@ virQEMUCapsCPUDefsToModels(virArch arch, continue; =20 if (vendors) - vendor =3D g_strdup(virCPUGetVendorForModel(arch, cpu->name)); + vendor =3D virCPUGetVendorForModel(arch, cpu->name); =20 virDomainCapsCPUModelsAdd(cpuModels, cpu->name, cpu->usable, cpu->blockers, cpu->deprecated, vendor); --=20 2.35.1