qemu/linux-user
Daniel P. Berrangé 5171b794d4 linux-user: fix resource leaks in gen-vdso
There are a number of resource leaks in gen-vdso. In theory they are
harmless because this is a short lived process, but when building QEMU
with --extra-cflags="-fsanitize=address" problems ensure. The gen-vdso
program is run as part of the build, and that aborts due to the
sanitizer identifying memory leaks, leaving QEMU unbuildable.

FAILED: libqemu-x86_64-linux-user.a.p/vdso.c.inc
/var/home/berrange/src/virt/qemu/build/linux-user/gen-vdso -o libqemu-x86_64-linux-user.a.p/vdso.c.inc ../linux-user/x86_64/vdso.so

=================================================================
==1696332==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 2968 byte(s) in 1 object(s) allocated from:
    #0 0x56495873f1f3  (/var/home/berrange/src/virt/qemu/build/linux-user/gen-vdso+0xa11f3) (BuildId: b69e241ad44719b6f3934f3c71dfc6727e8bdb12)
    #1 0x564958780b90  (/var/home/berrange/src/virt/qemu/build/linux-user/gen-vdso+0xe2b90) (BuildId: b69e241ad44719b6f3934f3c71dfc6727e8bdb12)

This complaint is about the 'buf' variable, however, the FILE objects
are also leaked in some error scenarios, so this fix refactors the
cleanup paths to fix all leaks. For completeness it also reports an
error if fclose() fails on 'inf'.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Tested-by: Arusekk <floss@arusekk.pl>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20250513150346.1328217-1-berrange@redhat.com>
2025-06-23 11:46:33 -07:00
..
aarch64 linux-user/aarch64: Remove unused get/put_user macros 2025-03-14 10:49:20 +00:00
alpha user: Prefer cached CpuClass over CPU_GET_CLASS() macro 2025-03-09 17:00:47 +01:00
arm linux-user/arm: Fix return value of SYS_cacheflush 2025-06-16 11:26:25 +01:00
generic linux-user: Move TARGET_SA_RESTORER out of generic/signal.h 2025-02-18 08:29:03 -08:00
hexagon user: Move 'linux-user/cpu_loop-common.h' -> 'user/cpu_loop.h' 2024-12-20 17:44:57 +01:00
hppa linux-user/hppa: Send proper si_code on SIGFPE exception 2025-05-17 13:20:17 +02:00
i386 linux-user: Move TARGET_SA_RESTORER out of generic/signal.h 2025-02-18 08:29:03 -08:00
include linux-user: cleanup unused linux-user/include/host directories 2023-08-08 20:44:08 +02:00
loongarch64 linux-user/loongarch64: Decode BRK break codes for FPE signals 2025-04-24 10:46:09 +08:00
m68k linux-user: Move TARGET_SA_RESTORER out of generic/signal.h 2025-02-18 08:29:03 -08:00
microblaze linux-user: Move TARGET_SA_RESTORER out of generic/signal.h 2025-02-18 08:29:03 -08:00
mips user: Move 'linux-user/cpu_loop-common.h' -> 'user/cpu_loop.h' 2024-12-20 17:44:57 +01:00
mips64 target/ppc: Fix lxvx/stxvx facility check 2024-09-27 10:32:29 +01:00
openrisc user: Move 'linux-user/cpu_loop-common.h' -> 'user/cpu_loop.h' 2024-12-20 17:44:57 +01:00
ppc linux-user: Move TARGET_SA_RESTORER out of generic/signal.h 2025-02-18 08:29:03 -08:00
riscv user: Move 'linux-user/cpu_loop-common.h' -> 'user/cpu_loop.h' 2024-12-20 17:44:57 +01:00
s390x linux-user: Move TARGET_SA_RESTORER out of generic/signal.h 2025-02-18 08:29:03 -08:00
sh4 linux-user: Move TARGET_SA_RESTORER out of generic/signal.h 2025-02-18 08:29:03 -08:00
sparc linux-user: Add missing /proc/cpuinfo fields for sparc 2025-01-16 20:57:17 -08:00
x86_64 linux-user: Move TARGET_SA_RESTORER out of generic/signal.h 2025-02-18 08:29:03 -08:00
xtensa cleanup: Drop pointless return at end of function 2025-04-24 09:33:42 +02:00
elfload.c linux-user/aarch64: Update hwcap bits from 6.14 2025-06-23 11:44:47 -07:00
errnos.c.inc linux-user: Simplify host <-> target errno conversion using macros 2021-07-12 21:53:35 +02:00
exit.c accel/tcg: Move perf and debuginfo support to tcg/ 2024-01-29 21:04:10 +10:00
fd-trans.c linux-user: netlink: Add missing QEMU_IFLA entries 2025-01-24 13:58:40 +01:00
fd-trans.h linux-user: fix timerfd read endianness conversion 2023-03-10 20:42:00 +01:00
flat.h linux-user/flatload.c: Remove unused bFLT shared-library and ZFLAT code 2024-04-25 10:21:06 +01:00
flatload.c include/exec: Split out mmap-lock.h 2025-04-23 14:08:17 -07:00
gen-vdso-elfn.c.inc linux-user: Fix GDB complaining about system-supplied DSO string table index 2024-11-05 10:36:08 +00:00
gen-vdso.c linux-user: fix resource leaks in gen-vdso 2025-06-23 11:46:33 -07:00
ioctls.h linux-user: Add ioctl for BLKBSZSET 2024-06-05 09:04:30 -07:00
linux_loop.h linux-user: implement more loop ioctls 2021-11-29 14:54:17 +01:00
linuxload.c {linux,bsd}-user: Introduce get_task_state() 2024-03-06 12:35:19 +00:00
loader.h linux-user: Report AArch64 hwcap2 fields above bit 31 2023-11-02 13:36:45 +00:00
main.c include/user: Convert GUEST_ADDR_MAX to a variable 2025-05-05 09:24:10 -07:00
meson.build plugins/api: split out binary path/start/end/entry code 2025-03-10 10:30:01 +00:00
mmap.c linux-user/mmap.c: fix "of of" typo in comment 2025-05-09 23:49:26 +03:00
plugin-api.c plugins/api: split out binary path/start/end/entry code 2025-03-10 10:30:01 +00:00
qemu.h exec: Restrict 'cpu_ldst.h' to accel/tcg/ 2025-04-23 15:07:32 -07:00
semihost.c semihosting: Remove qemu_semihosting_console_outs 2022-06-28 04:41:20 +05:30
signal-common.h user: Introduce user/signal.h 2025-02-10 13:47:59 +00:00
signal.c accel/tcg: Use vaddr in cpu_loop.h 2025-05-05 09:24:06 -07:00
socket.h Supply missing header guards 2019-06-12 13:20:21 +02:00
strace.c linux-user: Fix strace output for s390x mmap() 2024-11-22 14:20:38 -06:00
strace.h linux-user: Have do_syscall() use CPUArchState* instead of void* 2022-05-23 22:47:19 +02:00
strace.list linux-user: Trace rt_sigprocmask's sigsets 2024-10-22 13:45:03 -07:00
syscall.c linux-user: implement pgid field of /proc/self/stat 2025-05-28 08:07:59 +01:00
syscall_defs.h exec/cpu-all: remove BSWAP_NEEDED 2025-03-21 12:53:36 +01:00
syscall_types.h linux-user: Add FITRIM ioctl 2024-04-24 15:46:00 -07:00
thunk.c user: Move 'thunk.h' from 'exec/user' to 'user' 2024-05-03 17:21:20 +02:00
trace-events linux-user: Rename user_force_sig tracepoint to match function name 2022-01-18 12:41:42 +01:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00
uaccess.c meson: Make DEBUG_REMAP a meson option 2024-04-24 15:46:00 -07:00
uname.c linux-user: Remove pointless CPU{ARCH}State casts 2022-05-23 22:47:20 +02:00
uname.h linux-user: Have do_syscall() use CPUArchState* instead of void* 2022-05-23 22:47:19 +02:00
user-internals.h include: Remove 'exec/exec-all.h' 2025-04-30 12:45:05 -07:00
user-mmap.h user: Extract common MMAP API to 'user/mmap.h' 2025-03-09 14:54:32 +01:00
vm86.c linux-user/vm86: Fix compilation with Clang 2024-10-13 10:34:00 -07:00