diff mbox series

semihosting/uaccess.c: Replaced a malloc call with g_malloc.

Message ID 20230725080630.1083-1-dinglimin@cmss.chinamobile.com
State New
Headers show
Series semihosting/uaccess.c: Replaced a malloc call with g_malloc. | expand

Commit Message

dinglimin July 25, 2023, 8:06 a.m. UTC
Replaced a call to malloc() and its respective call to free() with g_malloc() and g_free().

Signed-off-by: dinglimin <dinglimin@cmss.chinamobile.com>
---
 semihosting/uaccess.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Michael Tokarev July 25, 2023, 8:13 a.m. UTC | #1
25.07.2023 11:06, dinglimin wrote:
> Replaced a call to malloc() and its respective call to free() with g_malloc() and g_free().
...
>   void *softmmu_lock_user(CPUArchState *env, target_ulong addr,
>                           target_ulong len, bool copy)
>   {
> -    void *p = malloc(len);
> +    void *p = g_malloc(len);
>       if (p && copy) {
>           if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) {
> -            free(p);
> -            p = NULL;
> +            g_free(p);
>           }
>       }
>       return p;

This is definitely wrong.

Hint: what this function will return if cpu_memory_rw_debug() fails?

/mjt
diff mbox series

Patch

diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c
index 8018828069..8f2e6f63ee 100644
--- a/semihosting/uaccess.c
+++ b/semihosting/uaccess.c
@@ -14,11 +14,10 @@ 
 void *softmmu_lock_user(CPUArchState *env, target_ulong addr,
                         target_ulong len, bool copy)
 {
-    void *p = malloc(len);
+    void *p = g_malloc(len);
     if (p && copy) {
         if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) {
-            free(p);
-            p = NULL;
+            g_free(p);
         }
     }
     return p;