[PATCH 1/3] bootstd: Fix memleak on errors in bootmeth_setup_iter_order()

Simon Glass sjg at chromium.org
Sat Feb 8 02:26:09 CET 2025


Hi Sam,

On Fri, 7 Feb 2025 at 18:11, Sam Protsenko <semen.protsenko at linaro.org> wrote:
>
> On Tue, Jan 14, 2025 at 7:14 AM Simon Glass <sjg at chromium.org> wrote:
> >
> > On Sat, 11 Jan 2025 at 20:42, Sam Protsenko <semen.protsenko at linaro.org> wrote:
> > >
> > > Free memory allocated for 'order' (array of bootmeths) on error paths in
> > > bootmeth_setup_iter_order() function.
> > >
> > > Fixes: c627cfc14c08 ("bootstd: Allow scanning for global bootmeths separately")
> > > Fixes: 10d16faa436c ("bootstd: Detect empty bootmeth")
> > > Signed-off-by: Sam Protsenko <semen.protsenko at linaro.org>
> > > ---
> > >  boot/bootmeth-uclass.c | 16 ++++++++++++----
> > >  1 file changed, 12 insertions(+), 4 deletions(-)
> > >
> >
> > Reviewed-by: Simon Glass <sjg at chromium.org>
> >
> > How about adding a test to check there is no leak? You can see
> > test/lib/abuf.c for similar tests.
>
> That might be a good idea, and I already have the test code handy. But
> frankly I wasn't able to successfully run the current bootstd test in
> sandbox, it fails before it can get to memleak check I added. Firstly,
> when I do:
>
>     $ make sandbox_defconfig
>     $ make -j32
>     $ ./u-boot -T -c "ut bootstd"
>
> it says:
>
>     MMC:   Can't map file 'mmc1.img': Invalid argument
>
> and I can see only empty (zero size) mmc1.img in my U-Boot source code
> root dir. Then I was able to trigger its creation (I guess) by running
> Python suite somehow, so it generated 20 MiB mmc1.img. But even with
> that added, I hit this error:
>
>     test/boot/bootdev.c:218, bootdev_test_order():
>         0 == bootflow_scan_first(((void *)0), ((void *)0), &iter, 0, &bflow):
>         Expected 0x0 (0), got 0xffffffed (-19)
>
> I've read corresponding doc [1] ("Tests" section), but still don't
> understand how can I successfully run the bootstd test locally. If you
> can help me out, I can send the memleak test you mentioned in v2.

You can run the bootstd tests with something like:

test/py/test.py -B sandbox --build-dir /tmp/b/sandbox -k bootstd

although it sounds like you have already figured that out. After you
do it once (to create the images) you can run the C tests directly as
you did above, but yes, sadly, some of the tests are affected by
others (with bootstd). You could take a look if you like.

Regards,
Simon

>
> Thanks!
>
> [1] doc/develop/bootstd/overview.rst


More information about the U-Boot mailing list