qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v4 04/12] fix qemu_alloc/qemu_free for linux-user su


From: Jean-Christophe DUBOIS
Subject: [Qemu-devel] [PATCH v4 04/12] fix qemu_alloc/qemu_free for linux-user subsystem
Date: Thu, 18 Jun 2009 22:50:11 +0200

From: Jean-Christophe Dubois <address@hidden(none)>

Signed-off-by: Jean-Christophe DUBOIS <address@hidden>
---
 linux-user/main.c    |   10 +++++-----
 linux-user/syscall.c |   16 ++++++++--------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 7eabd0c..f90d844 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -2549,7 +2549,7 @@ int main(int argc, char **argv, char **envp)
      * Prepare copy of argv vector for target.
      */
     target_argc = argc - optind;
-    target_argv = calloc(target_argc + 1, sizeof (char *));
+    target_argv = qemu_mallocz((target_argc + 1) * sizeof (char *));
     if (target_argv == NULL) {
        (void) fprintf(stderr, "Unable to allocate memory for target_argv\n");
        exit(1);
@@ -2583,15 +2583,15 @@ int main(int argc, char **argv, char **envp)
     }
 
     for (i = 0; i < target_argc; i++) {
-        free(target_argv[i]);
+        qemu_free(target_argv[i]);
     }
-    free(target_argv);
+    qemu_free(target_argv);
 
     for (wrk = target_environ; *wrk; wrk++) {
-        free(*wrk);
+        qemu_free(*wrk);
     }
 
-    free(target_environ);
+    qemu_free(target_environ);
 
     if (qemu_log_enabled()) {
         log_page_dump();
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 53a11ab..14df8aa 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2166,7 +2166,7 @@ static inline abi_long target_to_host_semarray(int semid, 
unsigned short **host_
 
     nsems = semid_ds.sem_nsems;
 
-    *host_array = malloc(nsems*sizeof(unsigned short));
+    *host_array = qemu_malloc(nsems*sizeof(unsigned short));
     array = lock_user(VERIFY_READ, target_addr,
                       nsems*sizeof(unsigned short), 1);
     if (!array)
@@ -2205,7 +2205,7 @@ static inline abi_long host_to_target_semarray(int semid, 
abi_ulong target_addr,
     for(i=0; i<nsems; i++) {
         __put_user((*host_array)[i], &array[i]);
     }
-    free(*host_array);
+    qemu_free(*host_array);
     unlock_user(array, target_addr, 1);
 
     return 0;
@@ -2451,11 +2451,11 @@ static inline abi_long do_msgsnd(int msqid, abi_long 
msgp,
 
     if (!lock_user_struct(VERIFY_READ, target_mb, msgp, 0))
         return -TARGET_EFAULT;
-    host_mb = malloc(msgsz+sizeof(long));
+    host_mb = qemu_malloc(msgsz+sizeof(long));
     host_mb->mtype = (abi_long) tswapl(target_mb->mtype);
     memcpy(host_mb->mtext, target_mb->mtext, msgsz);
     ret = get_errno(msgsnd(msqid, host_mb, msgsz, msgflg));
-    free(host_mb);
+    qemu_free(host_mb);
     unlock_user_struct(target_mb, msgp, 0);
 
     return ret;
@@ -2473,7 +2473,7 @@ static inline abi_long do_msgrcv(int msqid, abi_long msgp,
     if (!lock_user_struct(VERIFY_WRITE, target_mb, msgp, 0))
         return -TARGET_EFAULT;
 
-    host_mb = malloc(msgsz+sizeof(long));
+    host_mb = qemu_malloc(msgsz+sizeof(long));
     ret = get_errno(msgrcv(msqid, host_mb, msgsz, tswapl(msgtyp), msgflg));
 
     if (ret > 0) {
@@ -2488,7 +2488,7 @@ static inline abi_long do_msgrcv(int msqid, abi_long msgp,
     }
 
     target_mb->mtype = tswapl(host_mb->mtype);
-    free(host_mb);
+    qemu_free(host_mb);
 
 end:
     if (target_mb)
@@ -5756,7 +5756,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             struct linux_dirent *dirp;
             abi_long count = arg3;
 
-           dirp = malloc(count);
+           dirp = qemu_malloc(count);
            if (!dirp) {
                 ret = -TARGET_ENOMEM;
                 goto fail;
@@ -5794,7 +5794,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
                ret = count1;
                 unlock_user(target_dirp, arg2, ret);
             }
-           free(dirp);
+           qemu_free(dirp);
         }
 #else
         {
-- 
1.6.0.4





reply via email to

[Prev in Thread] Current Thread [Next in Thread]