qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Markus Armbruster <armbru@redhat.com>, Thomas Huth <thuth@redhat.com>
Cc: Elena Afanasova <eafanasova@gmail.com>,
	qemu-trivial@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [PATCH] elfload: use g_new instead of malloc
Date: Fri, 2 Oct 2020 10:08:07 -0500	[thread overview]
Message-ID: <17636b91-e111-1b60-4eb2-d526df4a6bb6@redhat.com> (raw)
In-Reply-To: <87eemhm2b9.fsf@dusky.pond.sub.org>


[-- Attachment #1.1: Type: text/plain, Size: 1441 bytes --]

On 10/2/20 3:58 AM, Markus Armbruster wrote:

>>>> @@ -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.
>>
>> Why? There is an exit(-1) right in front of it, so this is dead code...
>> well, maybe that should be done in a separate patch, or at least
>> mentioned in the patch description, though.
> 
> You're right; I missed the exit(-1).
> 
> Following the unpleasant odour spread by exit(-1)...  Aha, the
> function's behavior on error is inconsistent: sometimes it returns zero,
> sometimes it exits.

Eradicating exit(-1) (which is indistinguishable from exit(255), and
generally not what you want, unless your program is designed to
specifically invoke the immediate-exit semantics of xargs) is also a
worthwhile cleanup project.  But I agree with the advice for separate
patches for separate bugs.

> 
> Since the problem is bigger than just one dead return, I recommend
> leaving it to a separate patch, and keeping this one focused on g_new().
> 
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2020-10-02 15:36 UTC|newest]

Thread overview: 10+ 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-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 [this message]
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  9:55           ` Peter Maydell
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=17636b91-e111-1b60-4eb2-d526df4a6bb6@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=eafanasova@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=thuth@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).