Message ID | CAPtdW16tk5htGwMQohFnHboRna=TmasE4F-kv9wPPQSfHYad5A@mail.gmail.com |
---|---|
State | New |
Headers | show |
On Tue, Oct 6, 2015 at 3:06 PM, Harmandeep Kaur <write.harmandeep@gmail.com> wrote: > Convert malloc()/ calloc() calls to g_malloc()/ g_try_malloc()/ g_new0() > > Using GLib functions there is no need to check return value. > It aborts the execution if allocation fails (in most of the cases). This explains how the glib functions work, but for the commit description I suggest: Commit 7267c0947d7e8ae5dff7bafd932c3bc285f43e5c ("Use glib memory allocation and free functions") converted qemu_malloc() to g_malloc(). malloc(3) users were not converted since they didn't go through qemu_malloc(). All heap memory allocation should go through glib so we can take advantage of a single memory allocator and its debugging/tracing features. Stop using malloc(3) directly.
diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 98b5766..267aaa8 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1559,7 +1559,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); @@ -1575,7 +1575,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); @@ -1886,7 +1886,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;