xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH for-4.13] tools/libxl: Fix memory leak in libxl_cpuid_set()
@ 2020-06-12 17:32 Andrew Cooper
  2020-06-15 14:48 ` Ian Jackson
  2020-06-16  7:57 ` Jan Beulich
  0 siblings, 2 replies; 3+ messages in thread
From: Andrew Cooper @ 2020-06-12 17:32 UTC (permalink / raw)
  To: Xen-devel; +Cc: Andrew Cooper, Ian Jackson

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@citrix.com>
---
CC: Ian Jackson <Ian.Jackson@citrix.com>

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



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH for-4.13] tools/libxl: Fix memory leak in libxl_cpuid_set()
  2020-06-12 17:32 [PATCH for-4.13] tools/libxl: Fix memory leak in libxl_cpuid_set() Andrew Cooper
@ 2020-06-15 14:48 ` Ian Jackson
  2020-06-16  7:57 ` Jan Beulich
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Jackson @ 2020-06-15 14:48 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: Xen-devel, Jan Beulich

Andrew Cooper writes ("[PATCH for-4.13] tools/libxl: Fix memory leak in libxl_cpuid_set()"):
> 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@citrix.com>
> ---
> CC: Ian Jackson <Ian.Jackson@citrix.com>
> 
> Applicable for 4.13 and older.

Thanks.  I have committed this to 4.13 and 4.12.
4.12 is no longer supported for bugfixes like this one.

> 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.

That makes sense to me.

Ian.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH for-4.13] tools/libxl: Fix memory leak in libxl_cpuid_set()
  2020-06-12 17:32 [PATCH for-4.13] tools/libxl: Fix memory leak in libxl_cpuid_set() Andrew Cooper
  2020-06-15 14:48 ` Ian Jackson
@ 2020-06-16  7:57 ` Jan Beulich
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Beulich @ 2020-06-16  7:57 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: Xen-devel, Ian Jackson

On 12.06.2020 19:32, Andrew Cooper wrote:
> 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@citrix.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>
in case it helps.

Jan


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-06-16  7:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-12 17:32 [PATCH for-4.13] tools/libxl: Fix memory leak in libxl_cpuid_set() Andrew Cooper
2020-06-15 14:48 ` Ian Jackson
2020-06-16  7:57 ` Jan Beulich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).