diff options
-rw-r--r-- | collectors/ebpf.plugin/ebpf.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/collectors/ebpf.plugin/ebpf.c b/collectors/ebpf.plugin/ebpf.c index f73e99fdc3..b93c2dfd73 100644 --- a/collectors/ebpf.plugin/ebpf.c +++ b/collectors/ebpf.plugin/ebpf.c @@ -212,6 +212,7 @@ void clean_loaded_events() static void ebpf_exit(int sig) { close_ebpf_plugin = 1; + static int remove_pid = 0; // When both threads were not finished case I try to go in front this address, the collector will crash if (!thread_finished) { @@ -296,13 +297,19 @@ static void ebpf_exit(int sig) */ #ifdef LIBBPF_MAJOR_VERSION - if (default_btf) + if (default_btf) { btf__free(default_btf); + default_btf = NULL; + } #endif - char filename[FILENAME_MAX + 1]; - ebpf_pid_file(filename, FILENAME_MAX); - unlink(filename); + if (!remove_pid) { + remove_pid = 1; + char filename[FILENAME_MAX + 1]; + ebpf_pid_file(filename, FILENAME_MAX); + if (unlink(filename)) + error("Cannot remove PID file %s", filename); + } exit(sig); } |