diff options
author | xrs <xrs@mail36.net> | 2018-06-27 19:16:02 +0200 |
---|---|---|
committer | xrs <xrs@mail36.net> | 2018-06-27 19:16:02 +0200 |
commit | 599e34dd2a9e5b60547c00b667f6675f9739c84a (patch) | |
tree | 176f16adb6df140bf4aead3327df5d9c4c8b4f3d /src/cadet/gnunet-cadet.c | |
parent | 3c67615857af959b95ab7c133d07a06bb9cebdeb (diff) | |
download | gnunet-599e34dd2a9e5b60547c00b667f6675f9739c84a.tar.gz gnunet-599e34dd2a9e5b60547c00b667f6675f9739c84a.zip |
fix mem leak (when streaming large data streams)
Diffstat (limited to 'src/cadet/gnunet-cadet.c')
-rw-r--r-- | src/cadet/gnunet-cadet.c | 26 |
1 files changed, 25 insertions, 1 deletions
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 @@ | |||
27 | #include "gnunet_cadet_service.h" | 27 | #include "gnunet_cadet_service.h" |
28 | #include "cadet.h" | 28 | #include "cadet.h" |
29 | 29 | ||
30 | #define STREAM_BUFFER_SIZE 1024 // Pakets | ||
31 | //#define STREAM_BUFFER_SIZE 5*1024*1024 // 5 MB | ||
30 | 32 | ||
31 | /** | 33 | /** |
32 | * Option -P. | 34 | * Option -P. |
@@ -123,6 +125,8 @@ static struct GNUNET_SCHEDULER_Task *rd_task; | |||
123 | */ | 125 | */ |
124 | static struct GNUNET_SCHEDULER_Task *job; | 126 | static struct GNUNET_SCHEDULER_Task *job; |
125 | 127 | ||
128 | static unsigned int sent_pkt; | ||
129 | |||
126 | 130 | ||
127 | /** | 131 | /** |
128 | * Wait for input on STDIO and send it out over the #ch. | 132 | * Wait for input on STDIO and send it out over the #ch. |
@@ -228,6 +232,12 @@ shutdown_task (void *cls) | |||
228 | } | 232 | } |
229 | } | 233 | } |
230 | 234 | ||
235 | void * | ||
236 | mq_cb(void *cls) | ||
237 | { | ||
238 | listen_stdio (); | ||
239 | } | ||
240 | |||
231 | 241 | ||
232 | /** | 242 | /** |
233 | * Task run in stdio mode, after some data is available at stdin. | 243 | * Task run in stdio mode, after some data is available at stdin. |
@@ -248,6 +258,8 @@ read_stdio (void *cls) | |||
248 | 60000); | 258 | 60000); |
249 | if (data_size < 1) | 259 | if (data_size < 1) |
250 | { | 260 | { |
261 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
262 | "read() returned %s\n", strerror(errno)); | ||
251 | GNUNET_SCHEDULER_shutdown(); | 263 | GNUNET_SCHEDULER_shutdown(); |
252 | return; | 264 | return; |
253 | } | 265 | } |
@@ -262,9 +274,21 @@ read_stdio (void *cls) | |||
262 | data_size); | 274 | data_size); |
263 | GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), | 275 | GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), |
264 | env); | 276 | env); |
277 | |||
278 | sent_pkt++; | ||
279 | |||
265 | if (GNUNET_NO == echo) | 280 | if (GNUNET_NO == echo) |
266 | { | 281 | { |
267 | listen_stdio (); | 282 | // Use MQ's notification if the data of stdin is pooring in too fast. |
283 | if (STREAM_BUFFER_SIZE < sent_pkt) | ||
284 | { | ||
285 | GNUNET_MQ_notify_sent (env, mq_cb, cls); | ||
286 | sent_pkt = 0; | ||
287 | } | ||
288 | else | ||
289 | { | ||
290 | listen_stdio (); | ||
291 | } | ||
268 | } | 292 | } |
269 | else | 293 | else |
270 | { | 294 | { |