summaryrefslogtreecommitdiff
path: root/src/tools/oping/oping_server.c
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2016-10-24 10:47:13 +0200
committerdimitri staessens <[email protected]>2016-10-24 10:47:13 +0200
commitc4d765b68047176fb83ebc5a7462a68a5d051008 (patch)
treec7233cd16c5efc138120631c91e69a6336ce58d0 /src/tools/oping/oping_server.c
parentb23e3024d12c28b01426cc37d5adf03f9c1bea88 (diff)
downloadouroboros-c4d765b68047176fb83ebc5a7462a68a5d051008.tar.gz
ouroboros-c4d765b68047176fb83ebc5a7462a68a5d051008.zip
tools: Fix memory leaks in oping
Diffstat (limited to 'src/tools/oping/oping_server.c')
-rw-r--r--src/tools/oping/oping_server.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/tools/oping/oping_server.c b/src/tools/oping/oping_server.c
index bcd47f9a..720e71b6 100644
--- a/src/tools/oping/oping_server.c
+++ b/src/tools/oping/oping_server.c
@@ -75,23 +75,15 @@ void * server_thread(void *o)
struct timespec now = {0, 0};
struct timespec timeout = {0, 100 * MILLION};
int fd;
- fqueue_t * fq = fqueue_create();
- if (fq == NULL)
- return (void *) 1;
(void) o;
while (true) {
- int ret = flow_event_wait(server.flows, fq, &timeout);
- if (ret == -ETIMEDOUT)
+ if (flow_event_wait(server.flows, server.fq, &timeout)
+ == -ETIMEDOUT)
continue;
- if (ret < 0) {
- printf("Event error.\n");
- break;
- }
-
- while ((fd = fqueue_next(fq)) >= 0) {
+ while ((fd = fqueue_next(server.fq)) >= 0) {
msg_len = flow_read(fd, buf, OPING_BUF_SIZE);
if (msg_len < 0)
continue;
@@ -176,6 +168,12 @@ int server_main(void)
if (server.flows == NULL)
return 0;
+ server.fq = fqueue_create();
+ if (server.fq == NULL) {
+ flow_set_destroy(server.flows);
+ return -1;
+ }
+
pthread_create(&server.cleaner_pt, NULL, cleaner_thread, NULL);
pthread_create(&server.accept_pt, NULL, accept_thread, NULL);
pthread_create(&server.server_pt, NULL, server_thread, NULL);
@@ -185,6 +183,9 @@ int server_main(void)
pthread_cancel(server.server_pt);
pthread_cancel(server.cleaner_pt);
+ flow_set_destroy(server.flows);
+ fqueue_destroy(server.fq);
+
pthread_join(server.server_pt, NULL);
pthread_join(server.cleaner_pt, NULL);