From 599e34dd2a9e5b60547c00b667f6675f9739c84a Mon Sep 17 00:00:00 2001 From: xrs Date: Wed, 27 Jun 2018 19:16:02 +0200 Subject: [PATCH] fix mem leak (when streaming large data streams) --- src/cadet/gnunet-cadet.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c index 67cebf02b..4fedf1c05 100644 --- a/src/cadet/gnunet-cadet.c +++ b/src/cadet/gnunet-cadet.c @@ -27,6 +27,8 @@ #include "gnunet_cadet_service.h" #include "cadet.h" +#define STREAM_BUFFER_SIZE 1024 // Pakets +//#define STREAM_BUFFER_SIZE 5*1024*1024 // 5 MB /** * Option -P. @@ -123,6 +125,8 @@ static struct GNUNET_SCHEDULER_Task *rd_task; */ static struct GNUNET_SCHEDULER_Task *job; +static unsigned int sent_pkt; + /** * Wait for input on STDIO and send it out over the #ch. @@ -228,6 +232,12 @@ shutdown_task (void *cls) } } +void * +mq_cb(void *cls) +{ + listen_stdio (); +} + /** * Task run in stdio mode, after some data is available at stdin. @@ -248,6 +258,8 @@ read_stdio (void *cls) 60000); if (data_size < 1) { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "read() returned %s\n", strerror(errno)); GNUNET_SCHEDULER_shutdown(); return; } @@ -262,9 +274,21 @@ read_stdio (void *cls) data_size); GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env); + + sent_pkt++; + if (GNUNET_NO == echo) { - listen_stdio (); + // Use MQ's notification if the data of stdin is pooring in too fast. + if (STREAM_BUFFER_SIZE < sent_pkt) + { + GNUNET_MQ_notify_sent (env, mq_cb, cls); + sent_pkt = 0; + } + else + { + listen_stdio (); + } } else { -- 2.25.1