Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
libbpftune: fix netns fd leaks
in a few cases, we do not close netns fds; with large numbers of netns
we get significant leaks.

Signed-off-by: Alan Maguire <[email protected]>
Reported-by: Rob Landers <[email protected]>
  • Loading branch information
alan-maguire committed Nov 21, 2024
commit e7136b4d50ca13842613d25ee20e650fbe5954f8
14 changes: 10 additions & 4 deletions src/libbpftune.c
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,8 @@ int bpftune_sysctl_read(int netns_fd, const char *name, long *values)
out:
bpftune_netns_set(orig_netns_fd, NULL, true);
out_unset:
if (orig_netns_fd)
close(orig_netns_fd);
bpftune_cap_drop();
return err ? err : num_values;
}
Expand Down Expand Up @@ -957,6 +959,8 @@ int bpftune_sysctl_write(int netns_fd, const char *name, __u8 num_values, long *
out:
bpftune_netns_set(orig_netns_fd, NULL, true);
out_unset:
if (orig_netns_fd)
close(orig_netns_fd);
bpftune_cap_drop();
return err;
}
Expand Down Expand Up @@ -1311,10 +1315,12 @@ int bpftune_netns_info(int pid, int *fd, unsigned long *cookie)
} else {
bpftune_log(LOG_DEBUG, "setns failed for for fd %d\n",
netns_fd);
ret = -errno;
ret = err;
}
if (fdnew) {
if (ret || !fd)
close(netns_fd);
}
if (fdnew && !fd)
close(netns_fd);
if (orig_netns_fd > 0)
close(orig_netns_fd);
return ret;
Expand Down Expand Up @@ -1382,7 +1388,7 @@ static int bpftune_netns_find(unsigned long cookie)
}
while ((dirent = readdir(dir)) != NULL) {
char *endptr;
int netns_fd;
int netns_fd = 0;
long pid;

pid = strtol(dirent->d_name, &endptr, 10);
Expand Down