From nobody Mon May 6 05:57:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1591983208; cv=none; d=zohomail.com; s=zohoarc; b=YOznsJ1BhhC4ZG3jwdSZlUSVcRomk+IqNkowm8Efqc45jlujSNeljruAIXAs1/Q4uy3ues0gTPCgH2n2BPAU1R/jXN8uCvUAD40sokk4aS/Y+fefu5nF8YywpXK/akAtRPIe/mlCmUH+9eArQJ3WM77ArCKaoFYVaMuXLCKe+rQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591983208; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=ASznhphu9Y2xveCAyz9TCKXJvW0mgERtHy3X74W5r0g=; b=N7N1PatnuVWnWqR/Jo1KjQ6UARhCNvp0HrlNaf/Y7kciPnqMWIHBWJwZxVkITTMVERXBNAKeQ10q5HLtWQgg4tQaT7lkbrEHSNK4dE+N39o/FJbeR0ci+buH111iUgsCZT0LCay8nT/JX+CJn6Tmg29/iZsY69xC3PluyMHQmEs= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 159198320831364.32394808579932; Fri, 12 Jun 2020 10:33:28 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjnY2-0008Bm-Q4; Fri, 12 Jun 2020 17:32:58 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjnY1-0008Bh-Ra for xen-devel@lists.xenproject.org; Fri, 12 Jun 2020 17:32:57 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c047611d-acd2-11ea-b5f7-12813bfff9fa; Fri, 12 Jun 2020 17:32:56 +0000 (UTC) X-Inumbo-ID: c047611d-acd2-11ea-b5f7-12813bfff9fa Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: nMAyqSWmwSEvqO3XGye95m8HDLt9j7syn51Sm9Qxz5iTSSZ7CG9xbzTOUl2OihtrLlC7JtOOW0 aWdMGvJmTkRECfAbP3njl75jjtNexLEZ7obYJWEBAmGHuziKG0H0fHNChYHhJamjBwCaFrr45G i+qhypjFqmrEx/biepor8hPgFdSrOmKuuEmPYrA/XJsP/9kAnUUAxhUhRZVx32d8/1hZeuyRiT L1/ztmosGCrAO3A3FiIqpqoHC1HXIKQrBLZeSLN6F0M9bSw1L5nCuA2qWHDm5HKR51/ONLMTzw lTo= X-SBRS: 2.7 X-MesageID: 19927827 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.73,504,1583211600"; d="scan'208";a="19927827" From: Andrew Cooper To: Xen-devel Subject: [PATCH for-4.13] tools/libxl: Fix memory leak in libxl_cpuid_set() Date: Fri, 12 Jun 2020 18:32:27 +0100 Message-ID: <20200612173227.4103-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Ian Jackson Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" xc_cpuid_set() returns allocated memory via cpuid_res, which libxl needs to free() seeing as it discards the results. This is logically a backport of c/s b91825f628 "tools/libxc: Drop config_transformed parameter from xc_cpuid_set()" but rewritten as one call= er of xc_cpuid_set() does use returned values. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Ian Jackson Applicable for 4.13 and older. I'm not going to touch the Ocaml bindings - they're wrong in multiple ways including this memory leak, and we deleted them in 4.14 because they were totally unused. --- tools/libxl/libxl_cpuid.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/libxl/libxl_cpuid.c b/tools/libxl/libxl_cpuid.c index a78f08b927..083869dcf4 100644 --- a/tools/libxl/libxl_cpuid.c +++ b/tools/libxl/libxl_cpuid.c @@ -420,12 +420,17 @@ void libxl_cpuid_apply_policy(libxl_ctx *ctx, uint32_= t domid) void libxl_cpuid_set(libxl_ctx *ctx, uint32_t domid, libxl_cpuid_policy_list cpuid) { - int i; + int i, j; char *cpuid_res[4]; =20 for (i =3D 0; cpuid[i].input[0] !=3D XEN_CPUID_INPUT_UNUSED; i++) + { xc_cpuid_set(ctx->xch, domid, cpuid[i].input, (const char**)(cpuid[i].policy), cpuid_res); + + for (j =3D 0; j < ARRAY_SIZE(cpuid_res); ++j) + free(cpuid_res[j]); + } } =20 static const char *input_names[2] =3D { "leaf", "subleaf" }; --=20 2.11.0