Received: from eggs.gnu.org ([2001:4830:134:3::10]:33329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEams-00018g-3N for qemu-devel@nongnu.org; Fri, 23 Jan 2015 04:44:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YEamo-0003uX-Ti for qemu-devel@nongnu.org; Fri, 23 Jan 2015 04:44:22 -0500 Message-ID: <54C21610.7090808@sunrus.com.cn> Date: Fri, 23 Jan 2015 17:36:16 +0800 From: Chen Gang S MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] linux-user/syscall.c: Free the vec[i] in failure processing code block List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: riku.voipio@iki.fi 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 --- 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)