summaryrefslogtreecommitdiff
path: root/src/tools/oping/oping_server.c
diff options
context:
space:
mode:
authorSander Vrijders <[email protected]>2016-10-24 09:09:40 +0000
committerSander Vrijders <[email protected]>2016-10-24 09:09:40 +0000
commitb05290df28e380ddc789fd5e7eada95e9adef389 (patch)
tree016e36503f658e209f76e2b6bfc8d37bb23fc04c /src/tools/oping/oping_server.c
parent1c06b9ff80a2bf7ee6042534fee6098f7e452b59 (diff)
parentc4d765b68047176fb83ebc5a7462a68a5d051008 (diff)
downloadouroboros-b05290df28e380ddc789fd5e7eada95e9adef389.tar.gz
ouroboros-b05290df28e380ddc789fd5e7eada95e9adef389.zip
Merged in dstaesse/ouroboros/be-oping (pull request #277)
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);