[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] elfload: use g_new instead of malloc
From: |
Markus Armbruster |
Subject: |
Re: [PATCH] elfload: use g_new instead of malloc |
Date: |
Fri, 02 Oct 2020 07:05:50 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) |
Elena Afanasova <eafanasova@gmail.com> writes:
> Signed-off-by: Elena Afanasova <eafanasova@gmail.com>
> ---
> bsd-user/elfload.c | 92 +++++++++++++++-------------------------------
> 1 file changed, 30 insertions(+), 62 deletions(-)
>
> diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c
> index 32378af7b2..e10ca54eb7 100644
> --- a/bsd-user/elfload.c
> +++ b/bsd-user/elfload.c
> @@ -867,18 +867,14 @@ static abi_ulong load_elf_interp(struct elfhdr *
> interp_elf_ex,
> if (sizeof(struct elf_phdr) * interp_elf_ex->e_phnum >
> TARGET_PAGE_SIZE)
> return ~(abi_ulong)0UL;
>
> - elf_phdata = (struct elf_phdr *)
> - malloc(sizeof(struct elf_phdr) * interp_elf_ex->e_phnum);
> -
> - if (!elf_phdata)
> - return ~((abi_ulong)0UL);
> + elf_phdata = g_new(struct elf_phdr, interp_elf_ex->e_phnum);
>
> /*
> * If the size of this structure has changed, then punt, since
> * we will be doing the wrong thing.
> */
> if (interp_elf_ex->e_phentsize != sizeof(struct elf_phdr)) {
> - free(elf_phdata);
> + g_free(elf_phdata);
> return ~((abi_ulong)0UL);
> }
>
> @@ -890,9 +886,8 @@ static abi_ulong load_elf_interp(struct elfhdr *
> interp_elf_ex,
> }
> if (retval < 0) {
> perror("load_elf_interp");
> + g_free(elf_phdata);
> exit(-1);
> - free (elf_phdata);
> - return retval;
Deleting return looks wrong.
> }
> #ifdef BSWAP_NEEDED
> eppnt = elf_phdata;
> @@ -940,7 +935,7 @@ static abi_ulong load_elf_interp(struct elfhdr *
> interp_elf_ex,
> if (error == -1) {
> /* Real error */
> close(interpreter_fd);
> - free(elf_phdata);
> + g_free(elf_phdata);
> return ~((abi_ulong)0UL);
> }
>
> @@ -983,7 +978,7 @@ static abi_ulong load_elf_interp(struct elfhdr *
> interp_elf_ex,
> PROT_READ|PROT_WRITE|PROT_EXEC,
> MAP_FIXED|MAP_PRIVATE|MAP_ANON, -1, 0);
> }
> - free(elf_phdata);
> + g_free(elf_phdata);
>
> *interp_load_addr = load_addr;
> return ((abi_ulong) interp_elf_ex->e_entry) + load_addr;
> @@ -1064,24 +1059,15 @@ 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);
> - if (!syms) {
> - free(s);
> - return;
> - }
> - s->disas_strtab = strings = malloc(strtab.sh_size);
> - if (!s->disas_strtab) {
> - free(s);
> - free(syms);
> - return;
> - }
> + s = g_new(struct syminfo, 1);
> + syms = g_new(symtab.sh_size, 1);
g_new() takes a struct type argument, symtab.sh_size is an expression.
I'm pretty sure this doesn't even compile.
I'm looking no further.
Nacked-by: Markus Armbruster <armbru@redhat.com>
[...]
- [PATCH] elfload: use g_new instead of malloc, Elena Afanasova, 2020/10/01
- Re: [PATCH] elfload: use g_new instead of malloc, Thomas Huth, 2020/10/01
- Re: [PATCH] elfload: use g_new instead of malloc,
Markus Armbruster <=
- Re: [PATCH] elfload: use g_new instead of malloc, Thomas Huth, 2020/10/02
- Re: [PATCH] elfload: use g_new instead of malloc, Markus Armbruster, 2020/10/02
- Re: [PATCH] elfload: use g_new instead of malloc, Eric Blake, 2020/10/02
- Re: [PATCH v2] elfload: use g_new/g_malloc and g_autofree, Elena Afanasova, 2020/10/04
- Re: [PATCH v2] elfload: use g_new/g_malloc and g_autofree, Markus Armbruster, 2020/10/05
- Re: [PATCH v2] elfload: use g_new/g_malloc and g_autofree, Peter Maydell, 2020/10/05
- Re: [PATCH v2] elfload: use g_new/g_malloc and g_autofree, Elena Afanasova, 2020/10/06