diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-05-06 21:32:36 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-05-06 21:32:46 +0200 |
commit | 3f29625866332d29e3ad666b35d8c7c3006f95d1 (patch) | |
tree | e889f3f80c09feb388042d9eb66cf23a841a3dc0 /src/dht | |
parent | 964f78df05ce848b96908ad0b931dfec1e182348 (diff) | |
download | gnunet-3f29625866332d29e3ad666b35d8c7c3006f95d1.tar.gz gnunet-3f29625866332d29e3ad666b35d8c7c3006f95d1.zip |
fix dht profiler memory leak
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/gnunet_dht_profiler.c | 76 |
1 files changed, 35 insertions, 41 deletions
diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c index bc75b67f5..477f33bf6 100644 --- a/src/dht/gnunet_dht_profiler.c +++ b/src/dht/gnunet_dht_profiler.c | |||
@@ -94,11 +94,6 @@ struct ActiveContext | |||
94 | struct GNUNET_DHT_Handle *dht; | 94 | struct GNUNET_DHT_Handle *dht; |
95 | 95 | ||
96 | /** | 96 | /** |
97 | * The data used for do a PUT. Will be NULL if a PUT hasn't been performed yet | ||
98 | */ | ||
99 | void *put_data; | ||
100 | |||
101 | /** | ||
102 | * The active context used for our DHT GET | 97 | * The active context used for our DHT GET |
103 | */ | 98 | */ |
104 | struct ActiveContext *get_ac; | 99 | struct ActiveContext *get_ac; |
@@ -114,9 +109,10 @@ struct ActiveContext | |||
114 | struct GNUNET_DHT_GetHandle *dht_get; | 109 | struct GNUNET_DHT_GetHandle *dht_get; |
115 | 110 | ||
116 | /** | 111 | /** |
117 | * The hash of the @e put_data | 112 | * The hashes of the values stored via this activity context. |
113 | * Array of length #num_puts_per_peer. | ||
118 | */ | 114 | */ |
119 | struct GNUNET_HashCode hash; | 115 | struct GNUNET_HashCode *hash; |
120 | 116 | ||
121 | /** | 117 | /** |
122 | * Delay task | 118 | * Delay task |
@@ -129,11 +125,6 @@ struct ActiveContext | |||
129 | unsigned int put_count; | 125 | unsigned int put_count; |
130 | 126 | ||
131 | /** | 127 | /** |
132 | * The size of the @e put_data | ||
133 | */ | ||
134 | uint16_t put_data_size; | ||
135 | |||
136 | /** | ||
137 | * The number of peers currently doing GET on our data | 128 | * The number of peers currently doing GET on our data |
138 | */ | 129 | */ |
139 | uint16_t nrefs; | 130 | uint16_t nrefs; |
@@ -266,11 +257,6 @@ static unsigned int total_put_path_length; | |||
266 | static unsigned int total_get_path_length; | 257 | static unsigned int total_get_path_length; |
267 | 258 | ||
268 | /** | 259 | /** |
269 | * List of all the peers contexts. | ||
270 | */ | ||
271 | struct Context **peer_contexts = NULL; | ||
272 | |||
273 | /** | ||
274 | * Counter to keep track of peers added to peer_context lists. | 260 | * Counter to keep track of peers added to peer_context lists. |
275 | */ | 261 | */ |
276 | static int peers_started = 0; | 262 | static int peers_started = 0; |
@@ -320,8 +306,8 @@ do_shutdown (void *cls) | |||
320 | { | 306 | { |
321 | if (NULL != ac->delay_task) | 307 | if (NULL != ac->delay_task) |
322 | GNUNET_SCHEDULER_cancel (ac->delay_task); | 308 | GNUNET_SCHEDULER_cancel (ac->delay_task); |
323 | if (NULL != ac->put_data) | 309 | if (NULL != ac->hash) |
324 | GNUNET_free (ac->put_data); | 310 | free (ac->hash); |
325 | if (NULL != ac->dht_put) | 311 | if (NULL != ac->dht_put) |
326 | GNUNET_DHT_put_cancel (ac->dht_put); | 312 | GNUNET_DHT_put_cancel (ac->dht_put); |
327 | if (NULL != ac->dht_get) | 313 | if (NULL != ac->dht_get) |
@@ -496,10 +482,6 @@ get_iter (void *cls, | |||
496 | struct ActiveContext *get_ac = ac->get_ac; | 482 | struct ActiveContext *get_ac = ac->get_ac; |
497 | struct Context *ctx = ac->ctx; | 483 | struct Context *ctx = ac->ctx; |
498 | 484 | ||
499 | /* Check the keys of put and get match or not. */ | ||
500 | GNUNET_assert (0 == memcmp (key, | ||
501 | &get_ac->hash, | ||
502 | sizeof (struct GNUNET_HashCode))); | ||
503 | /* we found the data we are looking for */ | 485 | /* we found the data we are looking for */ |
504 | DEBUG ("We found a GET request; %u remaining\n", | 486 | DEBUG ("We found a GET request; %u remaining\n", |
505 | n_gets - (n_gets_fail + n_gets_ok)); //FIXME: It always prints 1. | 487 | n_gets - (n_gets_fail + n_gets_ok)); //FIXME: It always prints 1. |
@@ -547,21 +529,23 @@ delayed_get (void *cls) | |||
547 | r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 529 | r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
548 | n_active); | 530 | n_active); |
549 | get_ac = &a_ac[r]; | 531 | get_ac = &a_ac[r]; |
550 | if (NULL != get_ac->put_data) | 532 | if (NULL != get_ac->hash) |
551 | break; | 533 | break; |
552 | } | 534 | } |
553 | get_ac->nrefs++; | 535 | get_ac->nrefs++; |
554 | ac->get_ac = get_ac; | 536 | ac->get_ac = get_ac; |
537 | r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
538 | num_puts_per_peer); | ||
555 | DEBUG ("GET_REQUEST_START key %s \n", | 539 | DEBUG ("GET_REQUEST_START key %s \n", |
556 | GNUNET_h2s((struct GNUNET_HashCode *) ac->put_data)); | 540 | GNUNET_h2s(&get_ac->hash[r])); |
557 | ac->dht_get = GNUNET_DHT_get_start (ac->dht, | 541 | ac->dht_get = GNUNET_DHT_get_start (ac->dht, |
558 | GNUNET_BLOCK_TYPE_TEST, | 542 | GNUNET_BLOCK_TYPE_TEST, |
559 | &get_ac->hash, | 543 | &get_ac->hash[r], |
560 | 1, /* replication level */ | 544 | 1, /* replication level */ |
561 | GNUNET_DHT_RO_NONE, | 545 | GNUNET_DHT_RO_NONE, |
562 | NULL, | 546 | NULL, |
563 | 0, /* extended query and size */ | 547 | 0, /* extended query and size */ |
564 | get_iter, | 548 | &get_iter, |
565 | ac); /* GET iterator and closure */ | 549 | ac); /* GET iterator and closure */ |
566 | n_gets++; | 550 | n_gets++; |
567 | 551 | ||
@@ -612,6 +596,8 @@ static void | |||
612 | delayed_put (void *cls) | 596 | delayed_put (void *cls) |
613 | { | 597 | { |
614 | struct ActiveContext *ac = cls; | 598 | struct ActiveContext *ac = cls; |
599 | char block[65536]; | ||
600 | size_t block_size; | ||
615 | 601 | ||
616 | ac->delay_task = NULL; | 602 | ac->delay_task = NULL; |
617 | if (0 == ac->put_count) | 603 | if (0 == ac->put_count) |
@@ -628,26 +614,25 @@ delayed_put (void *cls) | |||
628 | 614 | ||
629 | 615 | ||
630 | /* Generate and DHT PUT some random data */ | 616 | /* Generate and DHT PUT some random data */ |
631 | ac->put_data_size = 16; /* minimum */ | 617 | block_size = 16; /* minimum */ |
632 | ac->put_data_size += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 618 | block_size += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
633 | (63*1024)); | 619 | (63*1024)); |
634 | ac->put_data = GNUNET_malloc (ac->put_data_size); | ||
635 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, | 620 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, |
636 | ac->put_data, | 621 | block, |
637 | ac->put_data_size); | 622 | block_size); |
638 | GNUNET_CRYPTO_hash (ac->put_data, | ||
639 | ac->put_data_size, | ||
640 | &ac->hash); | ||
641 | DEBUG ("PUT_REQUEST_START key %s\n", | ||
642 | GNUNET_h2s ((struct GNUNET_HashCode *)ac->put_data)); | ||
643 | ac->put_count--; | 623 | ac->put_count--; |
624 | GNUNET_CRYPTO_hash (block, | ||
625 | block_size, | ||
626 | &ac->hash[ac->put_count]); | ||
627 | DEBUG ("PUT_REQUEST_START key %s\n", | ||
628 | GNUNET_h2s (&ac->hash[ac->put_count])); | ||
644 | ac->dht_put = GNUNET_DHT_put (ac->dht, | 629 | ac->dht_put = GNUNET_DHT_put (ac->dht, |
645 | &ac->hash, | 630 | &ac->hash[ac->put_count], |
646 | replication, | 631 | replication, |
647 | GNUNET_DHT_RO_RECORD_ROUTE, | 632 | GNUNET_DHT_RO_RECORD_ROUTE, |
648 | GNUNET_BLOCK_TYPE_TEST, | 633 | GNUNET_BLOCK_TYPE_TEST, |
649 | ac->put_data_size, | 634 | block_size, |
650 | ac->put_data, | 635 | block, |
651 | GNUNET_TIME_UNIT_FOREVER_ABS, /* expiration time */ | 636 | GNUNET_TIME_UNIT_FOREVER_ABS, /* expiration time */ |
652 | &put_cont, | 637 | &put_cont, |
653 | ac); /* continuation and its closure */ | 638 | ac); /* continuation and its closure */ |
@@ -696,6 +681,15 @@ dht_connected (void *cls, | |||
696 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 681 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
697 | delay_put.rel_value_us); | 682 | delay_put.rel_value_us); |
698 | ac->put_count = num_puts_per_peer; | 683 | ac->put_count = num_puts_per_peer; |
684 | ac->hash = calloc (ac->put_count, | ||
685 | sizeof (struct GNUNET_HashCode)); | ||
686 | if (NULL == ac->hash) | ||
687 | { | ||
688 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | ||
689 | "calloc"); | ||
690 | GNUNET_SCHEDULER_shutdown (); | ||
691 | return; | ||
692 | } | ||
699 | ac->delay_task = GNUNET_SCHEDULER_add_delayed (peer_delay_put, | 693 | ac->delay_task = GNUNET_SCHEDULER_add_delayed (peer_delay_put, |
700 | &delayed_put, | 694 | &delayed_put, |
701 | ac); | 695 | ac); |