summaryrefslogtreecommitdiff
path: root/src/tools/oping/oping_server.c
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2026-05-08 12:34:48 +0200
committerSander Vrijders <sander@ouroboros.rocks>2026-05-20 08:17:06 +0200
commit86dbd8db9b051c8d1e08071cb8aae180a799427a (patch)
tree9e2076e72ec5656cfcbd66e0b008c0db2cdacece /src/tools/oping/oping_server.c
parent1e75103b1546f1fc732c37c93b85510b4b4f8c81 (diff)
downloadouroboros-86dbd8db9b051c8d1e08071cb8aae180a799427a.tar.gz
ouroboros-86dbd8db9b051c8d1e08071cb8aae180a799427a.zip
tools: Fix server mutex init in oping
The pthread_mutex_init and pthread_mutex_destroy were missing, resulting in undefined behaviour. Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks> Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src/tools/oping/oping_server.c')
-rw-r--r--src/tools/oping/oping_server.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/tools/oping/oping_server.c b/src/tools/oping/oping_server.c
index 33af28c4..e98ca040 100644
--- a/src/tools/oping/oping_server.c
+++ b/src/tools/oping/oping_server.c
@@ -237,6 +237,14 @@ int server_main(void)
return -1;
}
+ if (pthread_mutex_init(&server.lock, NULL)) {
+ fqueue_destroy(server.fq);
+ fset_destroy(server.flows);
+ return -1;
+ }
+
+ memset(server.times, 0, sizeof(server.times));
+
pthread_create(&server.cleaner_pt, NULL, cleaner_thread, NULL);
if (server.busy) {
@@ -255,11 +263,13 @@ int server_main(void)
pthread_cancel(server.cleaner_pt);
- fset_destroy(server.flows);
- fqueue_destroy(server.fq);
-
+ /* Join cancellable threads before tearing down their fset. */
pthread_join(server.server_pt, NULL);
pthread_join(server.cleaner_pt, NULL);
+ pthread_mutex_destroy(&server.lock);
+ fset_destroy(server.flows);
+ fqueue_destroy(server.fq);
+
return 0;
}