[PATCH 1/4] bpf: fix file descriptor leak

Kris Van Hees <[email protected]>
Newsgroups dev.linux.lists.dtrace
Message-ID <BY5PR10MB398729B40B695D3F3B541D3DC2CEA@BY5PR10MB3987.namprd10.prod.outlook.com>
When a BPF program has been attached to a perf event, it is safe to
close its file descriptor.

Signed-off-by: Kris Van Hees <[email protected]>
---
 libdtrace/dt_bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libdtrace/dt_bpf.c b/libdtrace/dt_bpf.c
index 0223764a..28eb890e 100644
--- a/libdtrace/dt_bpf.c
+++ b/libdtrace/dt_bpf.c
@@ -1385,8 +1385,8 @@ dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags)
 		if (prp->prov->impl->attach)
 			rc = prp->prov->impl->attach(dtp, prp, fd);
 
+		close(fd);
 		if (rc < 0 && !(prp->flags & DT_PROBE_FLAG_OPTIONAL)) {
-			close(fd);
 			dt_attach_error(dtp, rc,
 					prp->desc->prv, prp->desc->mod,
 					prp->desc->fun, prp->desc->prb);
-- 
2.43.5
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.