Skip to content

Commit

Permalink
bpf: prevent double-close
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Feb 26, 2021
1 parent 2763000 commit 021833d
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/lxc/cgroups/cgroup2_devices.c
Expand Up @@ -67,10 +67,7 @@ void bpf_program_free(struct bpf_program *prog)

(void)bpf_program_cgroup_detach(prog);

if (prog->kernel_fd >= 0)
close(prog->kernel_fd);
free(prog->instructions);
close_prot_errno_disarm(prog->fd_cgroup);
free(prog);
}

Expand Down Expand Up @@ -437,8 +434,8 @@ int bpf_program_cgroup_detach(struct bpf_program *prog)
return 0;

/* Ensure that these fds are wiped. */
fd_cgroup = prog->fd_cgroup;
fd_kernel = prog->kernel_fd;
fd_cgroup = move_fd(prog->fd_cgroup);
fd_kernel = move_fd(prog->kernel_fd);

if (fd_cgroup < 0 || fd_kernel < 0)
return 0;
Expand Down

0 comments on commit 021833d

Please sign in to comment.