From 2e38d22074e1f0a9eac5da25fae35028e6b9fd1c Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Tue, 19 Mar 2024 09:53:02 +0100 Subject: [PATCH] fix(userspace/libscap): fix memleak in scap-open example when killed by signal handler. Signed-off-by: Federico Di Pierro --- userspace/libscap/examples/01-open/scap_open.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/userspace/libscap/examples/01-open/scap_open.c b/userspace/libscap/examples/01-open/scap_open.c index e68bc58202..59a05a2f8f 100644 --- a/userspace/libscap/examples/01-open/scap_open.c +++ b/userspace/libscap/examples/01-open/scap_open.c @@ -890,7 +890,9 @@ void print_stats() static void signal_callback(int signal) { + scap_stop_capture(g_h); print_stats(); + scap_close(g_h); exit(EXIT_SUCCESS); } @@ -987,8 +989,5 @@ int main(int argc, char** argv) g_nevts++; } - scap_stop_capture(g_h); - print_stats(); - scap_close(g_h); - return EXIT_SUCCESS; + signal_callback(-1); }