From: Thierry Reding <thierry.reding@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] fdtdec: test: Fix memory leak
Date: Tue, 21 May 2019 12:21:26 +0200 [thread overview]
Message-ID: <20190521102126.GA29166@ulmo> (raw)
In-Reply-To: <CAPnjgZ2BQSP=dchCxXtWBeWjYw6nN37qb4EVffWdnirU94BLsg@mail.gmail.com>
On Mon, May 20, 2019 at 02:51:08PM -0600, Simon Glass wrote:
> Hi Thierry,
>
> On Mon, 20 May 2019 at 10:05, Thierry Reding <thierry.reding@gmail.com> wrote:
> >
> > From: Thierry Reding <treding@nvidia.com>
> >
> > Free the memory allocated to store the test FDT upon test completion to
> > avoid leaking the memory. We don't bother cleaning up on test failure
> > since the code is broken in that case and should be fixed, in which case
> > the leak would also go away.
> >
> > Reported-by: Tom Rini <tom.rini@gmail.com>
> > Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> > Signed-off-by: Thierry Reding <treding@nvidia.com>
> > ---
> > lib/fdtdec_test.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/lib/fdtdec_test.c b/lib/fdtdec_test.c
> > index f6defe16c5a6..54efcc3d46ac 100644
> > --- a/lib/fdtdec_test.c
> > +++ b/lib/fdtdec_test.c
> > @@ -138,6 +138,7 @@ static int run_test(const char *aliases, const char *nodes, const char *expect)
> > }
> >
> > printf("pass\n");
> > + free(blob);
>
> Strictly speaking, CHECKVAL() can cause a function return in the case
> of an error.
>
> So a better solution might be to put the code after the malloc() into
> a separate function.
When Heinrich suggested this fix he brought up the same issue, but
concluded, and I agree with him, that it wasn't worth addressing the
CHECKVAL case because if CHECKVAL failed, our code was buggy and would
need fixing, at which point the leak would go away along with the bug.
Do you feel strongly about reworking this so it doesn't leak in the
error case either?
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190521/5fa2473b/attachment.sig>
next prev parent reply other threads:[~2019-05-21 10:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-20 16:05 [U-Boot] [PATCH 1/2] fdtdec: test: Fix memory leak Thierry Reding
2019-05-20 16:05 ` [U-Boot] [PATCH 2/2] fdtdec: Remove fdt_{addr,size}_unpack() Thierry Reding
2019-05-22 13:21 ` Simon Glass
2019-05-20 20:51 ` [U-Boot] [PATCH 1/2] fdtdec: test: Fix memory leak Simon Glass
2019-05-21 10:21 ` Thierry Reding [this message]
2019-05-21 16:43 ` Simon Glass
2019-06-28 13:54 ` Simon Glass
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=20190521102126.GA29166@ulmo \
--to=thierry.reding@gmail.com \
--cc=u-boot@lists.denx.de \
/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