* [Qemu-devel] [PATCH] linux-user/syscall.c: Free the vec[i] in failure processing code block
@ 2015-01-23 9:36 Chen Gang S
2015-01-23 9:53 ` Chen Gang S
0 siblings, 1 reply; 2+ messages in thread
From: Chen Gang S @ 2015-01-23 9:36 UTC (permalink / raw)
To: riku.voipio; +Cc: QEMU Trivial, qemu-devel
When failure occurs during allocating vec[i], also need free all
allocated vec[i] in failure processing code block before return.
If error is EFAULT when "i == 0", vec[i].iov_base is NULL, then can just
skip it, so can still use "while (--i >= 0)" for the free looping.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
---
linux-user/syscall.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 290fdea..e6a8e49 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1873,6 +1873,11 @@ static struct iovec *lock_iovec(int type, abi_ulong target_addr,
return vec;
fail:
+ while (--i >= 0) {
+ if (tswapal(vec[i].iov_len) > 0) {
+ unlock_user(vec[i].iov_base, base, 0);
+ }
+ }
unlock_user(target_vec, target_addr, 0);
fail2:
free(vec);
--
1.9.3 (Apple Git-50)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] linux-user/syscall.c: Free the vec[i] in failure processing code block
2015-01-23 9:36 [Qemu-devel] [PATCH] linux-user/syscall.c: Free the vec[i] in failure processing code block Chen Gang S
@ 2015-01-23 9:53 ` Chen Gang S
0 siblings, 0 replies; 2+ messages in thread
From: Chen Gang S @ 2015-01-23 9:53 UTC (permalink / raw)
To: riku.voipio; +Cc: QEMU Trivial, qemu-devel
On 1/23/15 17:36, Chen Gang S wrote:
> When failure occurs during allocating vec[i], also need free all
> allocated vec[i] in failure processing code block before return.
>
> If error is EFAULT when "i == 0", vec[i].iov_base is NULL, then can just
> skip it, so can still use "while (--i >= 0)" for the free looping.
>
> Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
> ---
> linux-user/syscall.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 290fdea..e6a8e49 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -1873,6 +1873,11 @@ static struct iovec *lock_iovec(int type, abi_ulong target_addr,
> return vec;
>
> fail:
> + while (--i >= 0) {
> + if (tswapal(vec[i].iov_len) > 0) {
> + unlock_user(vec[i].iov_base, base, 0);
Oh, sorry, base is undefined here. I shall send patch v2 for it.
> + }
> + }
> unlock_user(target_vec, target_addr, 0);
> fail2:
> free(vec);
>
--
Chen Gang
Open, share, and attitude like air, water, and life which God blessed
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-01-23 9:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-23 9:36 [Qemu-devel] [PATCH] linux-user/syscall.c: Free the vec[i] in failure processing code block Chen Gang S
2015-01-23 9:53 ` Chen Gang S
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).