[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH for-4.13] tools/libxl: Fix memory leak in libxl_cpuid_set()


  • To: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Fri, 12 Jun 2020 18:32:27 +0100
  • Authentication-results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Ian Jackson <Ian.Jackson@xxxxxxxxxx>
  • Delivery-date: Fri, 12 Jun 2020 17:33:09 +0000
  • Ironport-sdr: nMAyqSWmwSEvqO3XGye95m8HDLt9j7syn51Sm9Qxz5iTSSZ7CG9xbzTOUl2OihtrLlC7JtOOW0 aWdMGvJmTkRECfAbP3njl75jjtNexLEZ7obYJWEBAmGHuziKG0H0fHNChYHhJamjBwCaFrr45G i+qhypjFqmrEx/biepor8hPgFdSrOmKuuEmPYrA/XJsP/9kAnUUAxhUhRZVx32d8/1hZeuyRiT L1/ztmosGCrAO3A3FiIqpqoHC1HXIKQrBLZeSLN6F0M9bSw1L5nCuA2qWHDm5HKR51/ONLMTzw lTo=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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 caller
of xc_cpuid_set() does use returned values.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Ian Jackson <Ian.Jackson@xxxxxxxxxx>

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];
 
     for (i = 0; cpuid[i].input[0] != XEN_CPUID_INPUT_UNUSED; i++)
+    {
         xc_cpuid_set(ctx->xch, domid, cpuid[i].input,
                      (const char**)(cpuid[i].policy), cpuid_res);
+
+        for (j = 0; j < ARRAY_SIZE(cpuid_res); ++j)
+            free(cpuid_res[j]);
+    }
 }
 
 static const char *input_names[2] = { "leaf", "subleaf" };
-- 
2.11.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.