From: Markus Armbruster <armbru@redhat.com>
To: Elena Afanasova <eafanasova@gmail.com>
Cc: qemu-devel@nongnu.org, qemu-trivial@nongnu.org
Subject: Re: [PATCH] elfload: use g_new instead of malloc
Date: Fri, 02 Oct 2020 07:05:50 +0200 [thread overview]
Message-ID: <87r1qhtdxt.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20201001123807.42978-1-eafanasova@gmail.com> (Elena Afanasova's message of "Thu, 1 Oct 2020 05:38:07 -0700")
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>
[...]
WARNING: multiple messages have this Message-ID (diff)
From: Markus Armbruster <armbru@redhat.com>
To: Elena Afanasova <eafanasova@gmail.com>
Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [PATCH] elfload: use g_new instead of malloc
Date: Fri, 02 Oct 2020 07:05:50 +0200 [thread overview]
Message-ID: <87r1qhtdxt.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20201001123807.42978-1-eafanasova@gmail.com> (Elena Afanasova's message of "Thu, 1 Oct 2020 05:38:07 -0700")
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>
[...]
next prev parent reply other threads:[~2020-10-02 5:06 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-01 12:38 [PATCH] elfload: use g_new instead of malloc Elena Afanasova
2020-10-01 15:01 ` Thomas Huth
2020-10-01 15:01 ` Thomas Huth
2020-10-02 5:05 ` Markus Armbruster [this message]
2020-10-02 5:05 ` Markus Armbruster
2020-10-02 5:18 ` Thomas Huth
2020-10-02 8:58 ` Markus Armbruster
2020-10-02 15:08 ` Eric Blake
2020-10-04 12:20 ` [PATCH v2] elfload: use g_new/g_malloc and g_autofree Elena Afanasova
2020-10-05 7:57 ` Markus Armbruster
2020-10-05 7:57 ` Markus Armbruster
2020-10-05 9:55 ` Peter Maydell
2020-10-05 9:55 ` Peter Maydell
2020-10-06 17:58 ` Elena Afanasova
2020-10-06 17:58 ` Elena Afanasova
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r1qhtdxt.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=eafanasova@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.