diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2024-05-19 15:56:18 +0200 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2024-05-22 22:08:44 +0200 |
commit | 9fb2db89e3c97e4f6cecf94ec9da5508ce32a470 (patch) | |
tree | c56388c8e8699d80f807014fa987c58fde9758b2 /src/libsystemd/sd-bus/sd-bus.c | |
parent | varlinkctl: when operating in --more mode, fail correcly on Varlink method error (diff) | |
download | systemd-9fb2db89e3c97e4f6cecf94ec9da5508ce32a470.tar.xz systemd-9fb2db89e3c97e4f6cecf94ec9da5508ce32a470.zip |
sd-bus: close peer pidfd
Do not leak the pidfd of the peer.
Fixes: 71be64064c9e ("sd-bus: add pidfd to the sd_bus_creds structure")
Diffstat (limited to 'src/libsystemd/sd-bus/sd-bus.c')
-rw-r--r-- | src/libsystemd/sd-bus/sd-bus.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index 22784e8f66..1a642cb197 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -152,6 +152,14 @@ void bus_close_inotify_fd(sd_bus *b) { b->n_inotify_watches = 0; } +static void bus_close_fds(sd_bus *b) { + assert(b); + + bus_close_io_fds(b); + bus_close_inotify_fd(b); + b->pidfd = safe_close(b->pidfd); +} + static void bus_reset_queues(sd_bus *b) { assert(b); @@ -192,8 +200,7 @@ static sd_bus* bus_free(sd_bus *b) { if (b->default_bus_ptr) *b->default_bus_ptr = NULL; - bus_close_io_fds(b); - bus_close_inotify_fd(b); + bus_close_fds(b); free(b->label); free(b->groups); @@ -1126,8 +1133,7 @@ static int bus_start_address(sd_bus *b) { assert(b); for (;;) { - bus_close_io_fds(b); - bus_close_inotify_fd(b); + bus_close_fds(b); bus_kill_exec(b); @@ -1802,8 +1808,7 @@ _public_ void sd_bus_close(sd_bus *bus) { * the bus object and the bus may be freed */ bus_reset_queues(bus); - bus_close_io_fds(bus); - bus_close_inotify_fd(bus); + bus_close_fds(bus); } _public_ sd_bus *sd_bus_close_unref(sd_bus *bus) { |