|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v9 02/15] microcode/amd: fix memory leak
Two buffers, '->equiv_cpu_table' and '->mpb', inside 'mc_amd' might be
allocated and in the error-handing path they are not freed properly.
Signed-off-by: Chao Gao <chao.gao@xxxxxxxxx>
Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
Changes in v9:
- use xzalloc() to get rid of explicitly initializing some fields
to NULL/0.
changes in v8:
- new
- it is found by reading code. No test is done.
---
xen/arch/x86/microcode_amd.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/xen/arch/x86/microcode_amd.c b/xen/arch/x86/microcode_amd.c
index 7a854c0..3069784 100644
--- a/xen/arch/x86/microcode_amd.c
+++ b/xen/arch/x86/microcode_amd.c
@@ -425,7 +425,7 @@ static int cpu_request_microcode(unsigned int cpu, const
void *buf,
goto out;
}
- mc_amd = xmalloc(struct microcode_amd);
+ mc_amd = xzalloc(struct microcode_amd);
if ( !mc_amd )
{
printk(KERN_ERR "microcode: Cannot allocate memory for microcode
patch\n");
@@ -479,6 +479,7 @@ static int cpu_request_microcode(unsigned int cpu, const
void *buf,
if ( error )
{
+ xfree(mc_amd->equiv_cpu_table);
xfree(mc_amd);
goto out;
}
@@ -491,8 +492,6 @@ static int cpu_request_microcode(unsigned int cpu, const
void *buf,
* It's possible the data file has multiple matching ucode,
* lets keep searching till the latest version
*/
- mc_amd->mpb = NULL;
- mc_amd->mpb_size = 0;
last_offset = offset;
while ( (error = get_ucode_from_buffer_amd(mc_amd, buf, bufsize,
&offset)) == 0 )
@@ -549,11 +548,13 @@ static int cpu_request_microcode(unsigned int cpu, const
void *buf,
if ( save_error )
{
- xfree(mc_amd);
uci->mc.mc_amd = mc_old;
+ mc_old = mc_amd;
}
- else
- xfree(mc_old);
+
+ xfree(mc_old->mpb);
+ xfree(mc_old->equiv_cpu_table);
+ xfree(mc_old);
out:
#if CONFIG_HVM
--
1.8.3.1
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |