Skip to contentSkip to conversation

linux-user/syscall.c: Free the vec[i] in failure processing code block

PATCH Superseded Chen Gang S 1 participant 2 messages Jan 23, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user/syscall.c: Free the vec[i] in failure processing code block

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.

---
 linux-user/syscall.c | 5 +++++
 1 file changed, 5 insertions(+)
linux-user/syscall.c +5 -0
index 290fdea..e6a8e49 100644
@@ -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);
Signature · 1 line
1.9.3 (Apple Git-50)
#1 lore raw
Quoted 16 lines · Chen Gang S

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.

---
 linux-user/syscall.c | 5 +++++
 1 file changed, 5 insertions(+)
linux-user/syscall.c +0 -0
index 290fdea..e6a8e49 100644

linux-user/syscall.c static struct iovec *lock_iovec(int type, abi_ulong target_addr, · line 1878

Quoted 6 lines
linux-user/syscall.c +3 -0
@@ -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.

Quoted 6 lines
linux-user/syscall.c +2 -0
+        }
+    }
     unlock_user(target_vec, target_addr, 0);
  fail2:
     free(vec);
Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed