tools/libxl: Fix memory leak in libxl_cpuid_set()
PATCH 1/1 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.
---
CC: Ian Jackson <[email protected]>
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(-)
tools/libxl/libxl_cpuid.c +6 -1
@@ -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" };
Signature · 1 line
2.11.0
Andrew Cooper writes ("[PATCH for-4.13] tools/libxl: Fix memory leak in libxl_cpuid_set()"):
Quoted 7 lines
xc_cpuid_set()returns allocated memory viacpuid_res, which libxl needs tofree()seeing as it discards the results.This is logically a backport of c/s
b91825f628"tools/libxc: Dropconfig_transformedparameter fromxc_cpuid_set()" but rewritten as one caller ofxc_cpuid_set()does use returned values.
Quoted 5 lines
Signed-off-by Andrew Cooper <[email protected]>---
CC: Ian Jackson <[email protected]>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.
Quoted 3 lines
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.
Quoted 8 lines · Andrew Cooper
xc_cpuid_set()returns allocated memory viacpuid_res, which libxl needs tofree()seeing as it discards the results.This is logically a backport of c/s
b91825f628"tools/libxc: Dropconfig_transformedparameter fromxc_cpuid_set()" but rewritten as one caller ofxc_cpuid_set()does use returned values.Signed-off-by Andrew Cooper <[email protected]>
in case it helps.
Jan