[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 04/17] linux-user/syscall.c: malloc()/calloc() to g_m
From: |
riku . voipio |
Subject: |
[Qemu-devel] [PULL 04/17] linux-user/syscall.c: malloc()/calloc() to g_malloc()/g_try_malloc()/g_new0() |
Date: |
Mon, 11 Jan 2016 16:16:06 +0200 |
From: Harmandeep Kaur <address@hidden>
Convert malloc()/ calloc() calls to g_malloc()/ g_try_malloc()/ g_new0()
All heap memory allocation should go through glib so that we can take
advantage of a single memory allocator and its debugging/tracing features.
Reviewed-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Harmandeep Kaur <address@hidden>
Signed-off-by: Riku Voipio <address@hidden>
---
linux-user/syscall.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index c216966..06a59b4 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1608,7 +1608,7 @@ set_timeout:
}
fprog.len = tswap16(tfprog->len);
- filter = malloc(fprog.len * sizeof(*filter));
+ filter = g_try_new(struct sock_filter, fprog.len);
if (filter == NULL) {
unlock_user_struct(tfilter, tfprog->filter, 1);
unlock_user_struct(tfprog, optval_addr, 1);
@@ -1624,7 +1624,7 @@ set_timeout:
ret = get_errno(setsockopt(sockfd, SOL_SOCKET,
SO_ATTACH_FILTER, &fprog, sizeof(fprog)));
- free(filter);
+ g_free(filter);
unlock_user_struct(tfilter, tfprog->filter, 1);
unlock_user_struct(tfprog, optval_addr, 1);
@@ -1935,7 +1935,7 @@ static struct iovec *lock_iovec(int type, abi_ulong
target_addr,
return NULL;
}
- vec = calloc(count, sizeof(struct iovec));
+ vec = g_try_new0(struct iovec, count);
if (vec == NULL) {
errno = ENOMEM;
return NULL;
@@ -1999,7 +1999,7 @@ static struct iovec *lock_iovec(int type, abi_ulong
target_addr,
}
unlock_user(target_vec, target_addr, 0);
fail2:
- free(vec);
+ g_free(vec);
errno = err;
return NULL;
}
@@ -2024,7 +2024,7 @@ static void unlock_iovec(struct iovec *vec, abi_ulong
target_addr,
unlock_user(target_vec, target_addr, 0);
}
- free(vec);
+ g_free(vec);
}
static inline int target_to_host_sock_type(int *type)
@@ -2726,14 +2726,14 @@ 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 = g_try_new(unsigned short, nsems);
if (!*host_array) {
return -TARGET_ENOMEM;
}
array = lock_user(VERIFY_READ, target_addr,
nsems*sizeof(unsigned short), 1);
if (!array) {
- free(*host_array);
+ g_free(*host_array);
return -TARGET_EFAULT;
}
@@ -2770,7 +2770,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);
+ g_free(*host_array);
unlock_user(array, target_addr, 1);
return 0;
@@ -3030,7 +3030,7 @@ 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 = g_try_malloc(msgsz + sizeof(long));
if (!host_mb) {
unlock_user_struct(target_mb, msgp, 0);
return -TARGET_ENOMEM;
@@ -3038,7 +3038,7 @@ static inline abi_long do_msgsnd(int msqid, abi_long msgp,
host_mb->mtype = (abi_long) tswapal(target_mb->mtype);
memcpy(host_mb->mtext, target_mb->mtext, msgsz);
ret = get_errno(msgsnd(msqid, host_mb, msgsz, msgflg));
- free(host_mb);
+ g_free(host_mb);
unlock_user_struct(target_mb, msgp, 0);
return ret;
@@ -3465,7 +3465,7 @@ static abi_long do_ioctl_fs_ioc_fiemap(const IOCTLEntry
*ie, uint8_t *buf_temp,
/* We can't fit all the extents into the fixed size buffer.
* Allocate one that is large enough and use it instead.
*/
- fm = malloc(outbufsz);
+ fm = g_try_malloc(outbufsz);
if (!fm) {
return -TARGET_ENOMEM;
}
@@ -3500,7 +3500,7 @@ static abi_long do_ioctl_fs_ioc_fiemap(const IOCTLEntry
*ie, uint8_t *buf_temp,
}
}
if (free_fm) {
- free(fm);
+ g_free(fm);
}
return ret;
}
@@ -7876,8 +7876,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
struct linux_dirent *dirp;
abi_long count = arg3;
- dirp = malloc(count);
- if (!dirp) {
+ dirp = g_try_malloc(count);
+ if (!dirp) {
ret = -TARGET_ENOMEM;
goto fail;
}
@@ -7913,7 +7913,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
ret = count1;
unlock_user(target_dirp, arg2, ret);
}
- free(dirp);
+ g_free(dirp);
}
#else
{
--
2.6.4
- [Qemu-devel] [PULL 00/17] linux-user queque, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 01/17] linux-user: add signalfd/signalfd4 syscalls, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 06/17] linux-user: rename TargetFdFunc to TargetFdDataFunc, and structure fields accordingly, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 04/17] linux-user/syscall.c: malloc()/calloc() to g_malloc()/g_try_malloc()/g_new0(),
riku . voipio <=
- [Qemu-devel] [PULL 05/17] linux-user: SOCK_PACKET uses network endian to encode protocol in socket(), riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 03/17] linux-user: in poll(), if nfds is 0, pfd can be NULL, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 02/17] linux-user: correctly align target_epoll_event, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 08/17] linux-user: manage bind with a socket of SOCK_PACKET type., riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 17/17] linux-user/mmap.c: Use end instead of real_end in target_mmap, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 11/17] linux-user/mmap.c: Always zero MAP_ANONYMOUS memory in mmap_frag(), riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 07/17] linux-user: add a function hook to translate sockaddr, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 14/17] linux-user/syscall.c: Use SOL_SOCKET instead of level for setsockopt(), riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 15/17] linux-user: Update m68k syscall definitions to match Linux 4.4., riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 10/17] linux-user, sh4: fix signal retcode address, riku . voipio, 2016/01/11