From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40847) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1af170-0003jy-IZ for qemu-devel@nongnu.org; Sun, 13 Mar 2016 04:10:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1af16x-0001gv-1N for qemu-devel@nongnu.org; Sun, 13 Mar 2016 04:10:54 -0400 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:36162) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1af16w-0001gr-NM for qemu-devel@nongnu.org; Sun, 13 Mar 2016 04:10:50 -0400 Received: by mail-wm0-x22f.google.com with SMTP id n186so69022665wmn.1 for ; Sun, 13 Mar 2016 00:10:50 -0800 (PST) References: <1457783505-21956-1-git-send-email-mbtamuli@gmail.com> From: Alex =?utf-8?Q?Benn=C3=A9e?= In-reply-to: <1457783505-21956-1-git-send-email-mbtamuli@gmail.com> Date: Sun, 13 Mar 2016 08:10:48 +0000 Message-ID: <87fuvu6bnb.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH 1/1] Converted malloc calls to g_malloc and g_new List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Mriyam Tamuli Cc: qemu-devel@nongnu.org Mriyam Tamuli writes: > Signed-off-by: Mriyam Tamuli While this is a good change you still need to ensure any corresponding free's are converted to g_free (and g_delete for g_new). > --- > block/iscsi.c | 2 +- > bsd-user/elfload.c | 12 ++++++------ > bsd-user/qemu.h | 2 +- > configure | 4 ++-- > disas/ia64.c | 2 +- > 5 files changed, 11 insertions(+), 11 deletions(-) > > diff --git a/block/iscsi.c b/block/iscsi.c > index 128ea79..2d6e5b4 100644 > --- a/block/iscsi.c > +++ b/block/iscsi.c > @@ -840,7 +840,7 @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs, > return &acb->common; > } > > - acb->task = malloc(sizeof(struct scsi_task)); > + acb->task = g_malloc(sizeof(struct scsi_task)); > if (acb->task == NULL) { g_malloc can't fail so the error leg can be removed. > error_report("iSCSI: Failed to allocate task for scsi command. %s", > iscsi_get_error(iscsi)); > diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c > index 0a6092b..74d7c79 100644 > --- a/bsd-user/elfload.c > +++ b/bsd-user/elfload.c > @@ -868,7 +868,7 @@ static abi_ulong load_elf_interp(struct elfhdr * interp_elf_ex, > return ~(abi_ulong)0UL; > > elf_phdata = (struct elf_phdr *) > - malloc(sizeof(struct elf_phdr) * interp_elf_ex->e_phnum); > + g_malloc(sizeof(struct elf_phdr) * interp_elf_ex->e_phnum); > > if (!elf_phdata) > return ~((abi_ulong)0UL); Again error checking becomes redundant. > @@ -1064,13 +1064,13 @@ static void load_symbols(struct elfhdr *hdr, int fd) > > found: > /* Now know where the strtab and symtab are. Snarf them. */ > - s = malloc(sizeof(*s)); > - syms = malloc(symtab.sh_size); > + s = g_malloc(sizeof(*s)); > + syms = g_malloc(symtab.sh_size); > if (!syms) { > free(s); > return; > } And here. > - s->disas_strtab = strings = malloc(strtab.sh_size); > + s->disas_strtab = strings = g_malloc(strtab.sh_size); > if (!s->disas_strtab) { > free(s); > free(syms); And here > @@ -1191,7 +1191,7 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, > } > > /* Now read in all of the header information */ > - elf_phdata = (struct elf_phdr *)malloc(elf_ex.e_phentsize*elf_ex.e_phnum); > + elf_phdata = g_new(elf_ex.e_phentsize * elf_ex.e_phnum); > if (elf_phdata == NULL) { > return -ENOMEM; > } > @@ -1244,7 +1244,7 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, > * is an a.out format binary > */ > > - elf_interpreter = (char *)malloc(elf_ppnt->p_filesz); > + elf_interpreter = g_new(elf_ppnt->p_filesz); > > if (elf_interpreter == NULL) { And here. > free (elf_phdata); > diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h > index 03b502a..ada4360 100644 > --- a/bsd-user/qemu.h > +++ b/bsd-user/qemu.h > @@ -357,7 +357,7 @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy > #ifdef DEBUG_REMAP > { > void *addr; > - addr = malloc(len); > + addr = g_malloc(len); > if (copy) > memcpy(addr, g2h(guest_addr), len); > else > diff --git a/configure b/configure > index 2b32876..5df672b 100755 > --- a/configure > +++ b/configure > @@ -3512,7 +3512,7 @@ fi > if test "$tcmalloc" = "yes" ; then > cat > $TMPC << EOF > #include > -int main(void) { malloc(1); return 0; } > +int main(void) { g_malloc(1); return 0; } I wouldn't touch the configure cases. There are used for probing the library support and in this case I don't see how it woould work considering only stdlib.h was included. > EOF > > if compile_prog "" "-ltcmalloc" ; then > @@ -3528,7 +3528,7 @@ fi > if test "$jemalloc" = "yes" ; then > cat > $TMPC << EOF > #include > -int main(void) { malloc(1); return 0; } > +int main(void) { g_malloc(1); return 0; } > EOF > > if compile_prog "" "-ljemalloc" ; then > diff --git a/disas/ia64.c b/disas/ia64.c > index 140754c..b0733ed 100644 > --- a/disas/ia64.c > +++ b/disas/ia64.c > @@ -10268,7 +10268,7 @@ static struct ia64_opcode * > make_ia64_opcode (ia64_insn opcode, const char *name, int place, int depind) > { > struct ia64_opcode *res = > - (struct ia64_opcode *) malloc (sizeof (struct ia64_opcode)); > + g_new(sizeof(struct ia64_opcode)); > res->name = strdup (name); > res->type = main_table[place].opcode_type; > res->num_outputs = main_table[place].num_outputs; -- Alex Bennée