Skip to content

Commit 9fb2db8

Browse files
cgzonesbluca
authored andcommitted
sd-bus: close peer pidfd
Do not leak the pidfd of the peer. Fixes: 71be640 ("sd-bus: add pidfd to the sd_bus_creds structure")
1 parent f5faf4e commit 9fb2db8

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/libsystemd/sd-bus/sd-bus.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ void bus_close_inotify_fd(sd_bus *b) {
152152
b->n_inotify_watches = 0;
153153
}
154154

155+
static void bus_close_fds(sd_bus *b) {
156+
assert(b);
157+
158+
bus_close_io_fds(b);
159+
bus_close_inotify_fd(b);
160+
b->pidfd = safe_close(b->pidfd);
161+
}
162+
155163
static void bus_reset_queues(sd_bus *b) {
156164
assert(b);
157165

@@ -192,8 +200,7 @@ static sd_bus* bus_free(sd_bus *b) {
192200
if (b->default_bus_ptr)
193201
*b->default_bus_ptr = NULL;
194202

195-
bus_close_io_fds(b);
196-
bus_close_inotify_fd(b);
203+
bus_close_fds(b);
197204

198205
free(b->label);
199206
free(b->groups);
@@ -1126,8 +1133,7 @@ static int bus_start_address(sd_bus *b) {
11261133
assert(b);
11271134

11281135
for (;;) {
1129-
bus_close_io_fds(b);
1130-
bus_close_inotify_fd(b);
1136+
bus_close_fds(b);
11311137

11321138
bus_kill_exec(b);
11331139

@@ -1802,8 +1808,7 @@ _public_ void sd_bus_close(sd_bus *bus) {
18021808
* the bus object and the bus may be freed */
18031809
bus_reset_queues(bus);
18041810

1805-
bus_close_io_fds(bus);
1806-
bus_close_inotify_fd(bus);
1811+
bus_close_fds(bus);
18071812
}
18081813

18091814
_public_ sd_bus *sd_bus_close_unref(sd_bus *bus) {

0 commit comments

Comments
 (0)