Convert malloc to g_try_malloc and free to g_free in
uaccess_lock_user.
Convert free to g_free in uaccess_unlock_user.
Signed-off-by: jiputer <jpaulma23@gmail.com>
---
Something to note, when len == 0 in uaccess_lock_user,
it will return a NULL pointer, instead of a non-null
pointer from malloc. Any read or writes on *p will report
EFAULT since it would be considered a bad address.
Patch is for this issue:
https://gitlab.com/qemu-project/qemu/-/work_items/1798
semihosting/uaccess.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c
index ff944d8c2f..71d7cc9006 100644
--- a/semihosting/uaccess.c
+++ b/semihosting/uaccess.c
@@ -17,10 +17,10 @@
void *uaccess_lock_user(CPUArchState *env, vaddr addr,
size_t len, bool copy)
{
- void *p = malloc(len);
+ void *p = g_try_malloc(len);
if (p && copy) {
if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) {
- free(p);
+ g_free(p);
p = NULL;
}
}
@@ -90,5 +90,5 @@ void uaccess_unlock_user(CPUArchState *env, void *p,
if (len) {
cpu_memory_rw_debug(env_cpu(env), addr, p, len, 1);
}
- free(p);
+ g_free(p);
}
--
2.43.0