efi_loader: Fix a memory leak when retrieving device paths from boot vars
authorIlias Apalodimas <ilias.apalodimas@linaro.org>
Thu, 27 Nov 2025 12:19:06 +0000 (14:19 +0200)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sat, 6 Dec 2025 10:43:28 +0000 (11:43 +0100)
commitad53505a4861ad7eec5c6a919ea39692d915e433
treed717e1b0537a915b6a100ee0ab18d73caca417d1
parent18e2a059ff3f04e21cf2f17af59d2c812cebc517
efi_loader: Fix a memory leak when retrieving device paths from boot vars

get_dp_device() is used to derive the device path from a boot variable.
However, if the last efi_get_variable_int() call fails, we return an
error without freeing 'buf'.

There's no need to call efi_get_variable_int() for variables we don't
know the size since we have the efi_get_var() wrapper.

Replace that in the two instances we use it. The first one will also
fix the memory leak.
A nice sideeffect is that the code size is also reduced, since we are
re-using functions instead of open coding them

$~ bloat-o-meter u-boot u-boot.new
add/remove: 0/0 grow/shrink: 1/2 up/down: 6/-196 (-190)
Function                                     old     new   delta
version_string                                70      76      +6
efi_launch_capsules                         2288    2196     -92
get_dp_device                                244     140    -104
Total: Before=1222331, After=1222141, chg -0.02%

Fixes: c74cd8bd08d1 ("efi_loader: capsule: add capsule_on_disk support")
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
lib/efi_loader/efi_capsule.c