diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-04-21 22:22:24 +0200 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2024-04-22 12:30:12 +0200 |
commit | 2fa480592d4f4334881361c5558f563e5ea4c9c3 (patch) | |
tree | 815aa17972b7bd5a27beff879f684896cb333f62 /src/tpm2-setup | |
parent | build(deps): bump pkg/arch from `ccc32ea` to `124b1da` (diff) | |
download | systemd-2fa480592d4f4334881361c5558f563e5ea4c9c3.tar.xz systemd-2fa480592d4f4334881361c5558f563e5ea4c9c3.zip |
sd-event: fix fd leak when fd is owned by IO event source
When an IO event source owns relevant fd, replacing with a new fd leaks
the previously assigned fd.
===
sd_event_add_io(event, &s, fd, ...);
sd_event_source_set_io_fd_own(s, true);
sd_event_source_set_io_fd(s, new_fd); <-- The previous fd is not closed.
sd_event_source_unref(s); <-- new_fd is closed as expected.
===
Without the change, valgrind reports the leak:
==998589==
==998589== FILE DESCRIPTORS: 4 open (3 std) at exit.
==998589== Open file descriptor 4:
==998589== at 0x4F119AB: pipe2 (in /usr/lib64/libc.so.6)
==998589== by 0x408830: test_sd_event_source_set_io_fd (test-event.c:862)
==998589== by 0x403302: run_test_table (tests.h:171)
==998589== by 0x408E31: main (test-event.c:935)
==998589==
==998589==
==998589== HEAP SUMMARY:
==998589== in use at exit: 0 bytes in 0 blocks
==998589== total heap usage: 33,305 allocs, 33,305 frees, 1,283,581 bytes allocated
==998589==
==998589== All heap blocks were freed -- no leaks are possible
==998589==
==998589== For lists of detected and suppressed errors, rerun with: -s
==998589== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Diffstat (limited to 'src/tpm2-setup')
0 files changed, 0 insertions, 0 deletions