[PATCH master 16/39] efi: fix unreachable free in efi_set_variable_printf
Ahmad Fatoum
a.fatoum at pengutronix.de
Mon Feb 16 00:44:16 PST 2026
The return statement before the free() calls makes them unreachable,
leaking both buf and buf16 on every call. Store the return value,
free the buffers, then return.
Co-Authored-By: Claude Opus 4.6 <noreply at anthropic.com>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
efi/efivar.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/efi/efivar.c b/efi/efivar.c
index 1e82afcb8798..16c3228dc79b 100644
--- a/efi/efivar.c
+++ b/efi/efivar.c
@@ -96,18 +96,21 @@ int efi_set_variable_printf(char *name, efi_guid_t *vendor, const char *fmt, ...
va_list args;
char *buf;
wchar_t *buf16;
+ int ret;
va_start(args, fmt);
buf = xvasprintf(fmt, args);
va_end(args);
buf16 = xstrdup_char_to_wchar(buf);
- return efi_set_variable(name, vendor,
+ ret = efi_set_variable(name, vendor,
EFI_VARIABLE_BOOTSERVICE_ACCESS |
EFI_VARIABLE_RUNTIME_ACCESS, buf16,
(strlen(buf)+1) * sizeof(wchar_t));
free(buf);
free(buf16);
+
+ return ret;
}
int efi_set_variable_uint64_le(char *name, efi_guid_t *vendor, uint64_t value)
--
2.47.3
More information about the barebox
mailing list