From patchwork Mon Oct 5 03:32:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harmandeep Kaur X-Patchwork-Id: 526237 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id DBF3114090A for ; Mon, 5 Oct 2015 14:32:55 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=av23ZmU/; dkim-atps=neutral Received: from localhost ([::1]:44164 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZiwWD-0001pg-FR for incoming@patchwork.ozlabs.org; Sun, 04 Oct 2015 23:32:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49778) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZiwVq-0001WJ-JU for qemu-devel@nongnu.org; Sun, 04 Oct 2015 23:32:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZiwVo-00060V-93 for qemu-devel@nongnu.org; Sun, 04 Oct 2015 23:32:29 -0400 Received: from mail-ig0-x236.google.com ([2607:f8b0:4001:c05::236]:34794) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZiwVo-00060L-1s for qemu-devel@nongnu.org; Sun, 04 Oct 2015 23:32:28 -0400 Received: by igcpb10 with SMTP id pb10so54024485igc.1 for ; Sun, 04 Oct 2015 20:32:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=k0wBOZw4m7pIGtTlL9qLXKwUNwTNW3RjkWjZwsv3HB4=; b=av23ZmU/ptHD85gvHwZryIkNXLWlbrjcB4VPtunsxlutOf8o6BHL3nUq3BU+MXxPMV FGnfY9a0EcmYa2QqyJZyv5ejuM2aicS8EZcKI5EzkuTYAi5nGOhx71V+ERP1/LFyci0T JgWexdXqFPvy4b36jDWOwl1jxkG1dduKiMD6wejSEd7SGmVZbyr6EGUO9ec8vnWrBggr kGfQeRsKBNjpOLM+omWTq27ZbXL/1UlHhKZv8JmTQEoFF2YHOmaeTeVoHzVRmJ2ZKIXD Y/X0hBD2pZMZZIbbQV02i1MMk2VX3QgS5p9OFdxpcnI3Qz/weryDtcUouIN8PAEd636K ehQQ== MIME-Version: 1.0 X-Received: by 10.50.138.69 with SMTP id qo5mr4563562igb.50.1444015947447; Sun, 04 Oct 2015 20:32:27 -0700 (PDT) Received: by 10.79.105.198 with HTTP; Sun, 4 Oct 2015 20:32:27 -0700 (PDT) Date: Mon, 5 Oct 2015 09:02:27 +0530 Message-ID: From: Harmandeep Kaur To: qemu-devel X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4001:c05::236 Cc: Stefan Hajnoczi , Riku Voipio , Peter Maydell Subject: [Qemu-devel] [PATCH v4] linux-user/syscall.c: malloc()/calloc() to g_malloc()/g_try_malloc()/g_new0() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Convert malloc()/calloc() calls to g_malloc()/g_try_malloc()/g_new0() in linux-user/syscall.c file Signed-off-by: Harmandeep Kaur Reviewed-by: Stefan Hajnoczi --- v1->v2 convert the free() call in host_to_target_semarray() to g_free() and calls g_try_malloc(count) instead of g_try_malloc(sizeof(count)) v2->v3 used g_try_new() and friends to avoid overflow issues v3->v4 use g_free for unlock_iovec() and host_to_target_semarray(). linux-user/syscall.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) return NULL; @@ -1950,7 +1950,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; } @@ -1975,7 +1975,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) @@ -2677,14 +2677,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; } @@ -2721,7 +2721,7 @@ static inline abi_long host_to_target_semarray(int semid, abi_ulong target_addr, for(i=0; imtype = (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; @@ -7723,7 +7723,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 = g_try_malloc(sizeof(count)); if (!dirp) { ret = -TARGET_ENOMEM; goto fail; @@ -7760,7 +7760,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 { diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 98b5766..6e90141 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;