diff --git a/userspace/libscap/engine/bpf/scap_bpf.c b/userspace/libscap/engine/bpf/scap_bpf.c index 0d4385751c..29430a382f 100644 --- a/userspace/libscap/engine/bpf/scap_bpf.c +++ b/userspace/libscap/engine/bpf/scap_bpf.c @@ -1386,8 +1386,11 @@ int32_t scap_bpf_close(struct scap_engine_handle engine) for(int i = 0; i < BPF_MAPS_MAX; i++) { - close(handle->m_bpf_map_fds[i]); - handle->m_bpf_map_fds[i] = -1; + if(handle->m_bpf_map_fds[i] >= 0) + { + close(handle->m_bpf_map_fds[i]); + handle->m_bpf_map_fds[i] = -1; + } } return SCAP_SUCCESS;