qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
Cc: Max Reitz <mreitz@redhat.com>,
	qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	qemu-block@nongnu.org, Markus Armbruster <armbru@redhat.com>,
	Eric Blake <eblake@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] block/crypto: Simplify block_crypto_co_create_opts_luks to avoid a memory leak
Date: Thu, 5 Jul 2018 18:21:00 +0200	[thread overview]
Message-ID: <20180705162100.GO3309@localhost.localdomain> (raw)
In-Reply-To: <b7b181c1-7383-c76b-efd4-002f928707ac@amsat.org>

Am 05.07.2018 um 18:04 hat Philippe Mathieu-Daudé geschrieben:
> On 07/05/2018 07:20 AM, Kevin Wolf wrote:
> > Am 04.07.2018 um 17:02 hat Philippe Mathieu-Daudé geschrieben:
> >> After 1ec4f4160a1 Coverity reported:
> >>
> >>   Variable cryptoopts going out of scope leaks the storage it points to.
> >>
> >> Fixes: Coverity CID 1393782 (Resource leak)
> >> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> > 
> > I already sent a much simpler fix:
> > [PATCH] block/crypto: Fix memory leak in create error path
> 
> Oh OK I searched a bit but missed it.
> 
> > The only thing that is needed is replacing the return with a goto.
> > Splitting it in three different error paths is unnecessary because the
> > cleanup function handle NULL values just fine.
> 
> OK, good to know.
> 
> >> I think this check is superfluous but I respected the previous code:
> >>
> >>      ret = block_crypto_co_create_generic(bs, size, create_opts, errp);
> >>      if (ret > 0) {
> >>          ret = 0;
> >>      }
> > 
> > It is wrong, too. The old code keep the error code, goto fail skipped
> > the ret = 0.
> 
> So this is not particularly wrong but as superfluous as the current use :)
> 
> ret = 0 is only useful if block_crypto_co_create_generic() returned a
> value > 0, which seems unlikely.

Sorry, yes, you're right. I read 'if (ret < 0)' in your patch.

The reason for the seemingly superfluous error path is that you can add
new code behind it without having to modify the existing code.

Kevin

      reply	other threads:[~2018-07-05 16:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-04 15:02 [Qemu-devel] [PATCH] block/crypto: Simplify block_crypto_co_create_opts_luks to avoid a memory leak Philippe Mathieu-Daudé
2018-07-05 10:20 ` Kevin Wolf
2018-07-05 16:04   ` Philippe Mathieu-Daudé
2018-07-05 16:21     ` Kevin Wolf [this message]

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=20180705162100.GO3309@localhost.localdomain \
    --to=kwolf@redhat.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@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 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).