fix memory leak in aio_write_f
PATCH 1/1 fix memory leak in aio_write_f
From: Alex Jia <[email protected]>
Haven't released memory of 'ctx' before return.
--- qemu-io.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
qemu-io.c +1 -0
@@ -1248,6 +1248,7 @@ static int aio_write_f(int argc, char **argv)case 'P' : pattern =parse_pattern (optarg);if (pattern <0 ) { +free (ctx);return 0 ; }break ;
Signature · 1 line
1.7.1
PATCH 1/1 linux-user: fix memory leak in failure path
From: Alex Jia <[email protected]>
Haven't released memory of 'array' and 'host_mb' in failure paths.
--- linux-user/syscall.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
linux-user/syscall.c +4 -2
@@ -2523,8 +2523,10 @@ static inline abi_long do_semctl(int semid, int semnum, int cmd,case GETALL :case SETALL : err =target_to_host_semarray (semid, &array, target_su.array); -if (err) +if (err) { +free (array);return err; + } arg.array = array; ret =get_errno (semctl (semid, semnum, cmd, arg)); err =host_to_target_semarray (semid, target_su.array, &array);
@@ -2779,9 +2781,9 @@ static inline abi_long do_msgrcv(int msqid, abi_long msgp, } target_mb->mtype =tswapl (host_mb->mtype); -free (host_mb); end: +free (host_mb);if (target_mb)unlock_user_struct (target_mb, msgp,1 );return ret;
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH] linux-user: fix memory leak in failure path
Quoted 17 lines · On 28 September 2011 07:57, <[email protected]> wrote:
From: Alex Jia <[email protected]>
Haven't released memory of 'array' and '
host_mb' in failure paths.Signed-off-by Alex Jia <[email protected]>---
linux-user/syscall.c | 6 ++++--1 files changed, 4 insertions(+), 2 deletions(-)linux-user/syscall.c +0
-0@@ -2523,8 +2523,10 @@ static inline abi_long do_semctl(int semid, int semnum, int cmd,case GETALL:
case SETALL:
err =target_to_host_semarray(semid, &array, target_su.array);
Quoted 8 lines
- if (err)
+ if (err) {
+ free(array);
return err;
+ }
arg.array = array;
ret =get_errno(semctl(semid, semnum, cmd, arg)); err =host_to_target_semarray(semid, target_su.array, &array);
This is the wrong place to try to fix this. If target_to_host_semarray fails it should free() the buffer it malloc()ed itself, not rely on its caller to do the cleanup.
Quoted 11 lines
linux-user/syscall.c +0
-1@@ -2779,9 +2781,9 @@ static inline abi_long do_msgrcv(int msqid, abi_long msgp, } target_mb->mtype = tswapl(host_mb->mtype); - free(host_mb);end:
+ free(host_mb);
if (target_mb)
unlock_user_struct(target_mb, msgp, 1);
return ret;
This change is OK.
Also I note that target_to_host_semarray is doing a plain malloc() and not checking the return value. You should fix that while you're doing fixes in this area.
-- PMM
Re: [Qemu-devel] [PATCH] linux-user: fix memory leak in failure path
Quoted 21 lines · Peter Maydell
Quoted 20 lines · On 28 September 2011 07:57,<[email protected]> wrote:
From: Alex Jia<[email protected]>
Haven't released memory of 'array' and '
host_mb' in failure paths.Signed-off-by Alex Jia<[email protected]>--- linux-user/syscall.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)linux-user/syscall.c +2
-1@@ -2523,8 +2523,10 @@ static inline abi_long do_semctl(int semid, int semnum, int cmd,case GETALL :case SETALL : err =target_to_host_semarray (semid,&array, target_su.array); -if (err) +if (err) { +free (array);
Quoted 9 lines
linux-user/syscall.c static inline abi_long do_semctl(int semid, int semnum, int cmd,
Quoted 5 lines
linux-user/syscall.c +1
-0return err; + } arg.array = array; ret =get_errno (semctl (semid, semnum, cmd, arg)); err =host_to_target_semarray (semid, target_su.array,&array);This is the wrong place to try to fix this. If
target_to_host_semarrayfails it shouldfree()the buffer it malloc()ed itself, not rely on its caller to do the cleanup.
Yeah, caller shouldn't do this.
Quoted 13 lines
linux-user/syscall.c static inline abi_long do_msgrcv(int msqid, abi_long msgp, · line 2789
Quoted 11 lines
linux-user/syscall.c +1
-1@@ -2779,9 +2781,9 @@ static inline abi_long do_msgrcv(int msqid, abi_long msgp, } target_mb->mtype =tswapl (host_mb->mtype); -free (host_mb); end: +free (host_mb);if (target_mb)unlock_user_struct (target_mb, msgp,1 );return ret;This change is OK.
Quoted 3 lines
Also I note that
target_to_host_semarrayis doing a plainmalloc()and not checking the return value. You should fix that while you're doing fixes in this area.
Yeah, for return value check of malloc(), it seems many places haven't do it.
Thanks,
Alex
Quoted 1 line
-- PMM
Kevin Wolf
AppliedAm 28.09.2011 08:57, schrieb [email protected]:
Quoted 5 lines
From: Alex Jia <[email protected]>
Haven't released memory of 'ctx' before return.
Signed-off-by Alex Jia <[email protected]>
Thanks, applied to the block branch.
Kevin