diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-09-30 12:55:03 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-09-30 12:55:03 +0000 |
commit | 87ed5554b390cbf16a9bd15c4aec13ab34d7f080 (patch) | |
tree | 57716c8c85d0d8f8e3463f5a1b766f51b4f22405 /src/testbed | |
parent | ec7d72a656a180ecdd25507439add2656d5bcbae (diff) | |
download | gnunet-87ed5554b390cbf16a9bd15c4aec13ab34d7f080.tar.gz gnunet-87ed5554b390cbf16a9bd15c4aec13ab34d7f080.zip |
- fix misc. memleaks
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/gnunet-service-testbed_barriers.c | 33 | ||||
-rw-r--r-- | src/testbed/gnunet-service-testbed_links.c | 117 | ||||
-rw-r--r-- | src/testbed/gnunet-service-testbed_links.h | 7 | ||||
-rw-r--r-- | src/testbed/testbed_api_hosts.c | 2 |
4 files changed, 112 insertions, 47 deletions
diff --git a/src/testbed/gnunet-service-testbed_barriers.c b/src/testbed/gnunet-service-testbed_barriers.c index c1d5036eb..bffafd7ae 100644 --- a/src/testbed/gnunet-service-testbed_barriers.c +++ b/src/testbed/gnunet-service-testbed_barriers.c | |||
@@ -330,7 +330,10 @@ cleanup_clientctx (struct ClientCtx *ctx) | |||
330 | struct MessageQueue *mq; | 330 | struct MessageQueue *mq; |
331 | 331 | ||
332 | if (NULL != ctx->client) | 332 | if (NULL != ctx->client) |
333 | { | ||
334 | GNUNET_SERVER_client_set_user_context_ (ctx->client, NULL, 0); | ||
333 | GNUNET_SERVER_client_drop (ctx->client); | 335 | GNUNET_SERVER_client_drop (ctx->client); |
336 | } | ||
334 | if (NULL != ctx->tx) | 337 | if (NULL != ctx->tx) |
335 | GNUNET_SERVER_notify_transmit_ready_cancel (ctx->tx); | 338 | GNUNET_SERVER_notify_transmit_ready_cancel (ctx->tx); |
336 | if (NULL != (mq = ctx->mq_head)) | 339 | if (NULL != (mq = ctx->mq_head)) |
@@ -482,11 +485,11 @@ handle_barrier_wait (void *cls, struct GNUNET_SERVER_Client *client, | |||
482 | (void) memcpy (name, msg->name, name_len); | 485 | (void) memcpy (name, msg->name, name_len); |
483 | LOG_DEBUG ("Received BARRIER_WAIT for barrier `%s'\n", name); | 486 | LOG_DEBUG ("Received BARRIER_WAIT for barrier `%s'\n", name); |
484 | GNUNET_CRYPTO_hash (name, name_len, &key); | 487 | GNUNET_CRYPTO_hash (name, name_len, &key); |
488 | GNUNET_free (name); | ||
485 | if (NULL == (barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map, &key))) | 489 | if (NULL == (barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map, &key))) |
486 | { | 490 | { |
487 | GNUNET_break (0); | 491 | GNUNET_break (0); |
488 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 492 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
489 | GNUNET_free (name); | ||
490 | return; | 493 | return; |
491 | } | 494 | } |
492 | client_ctx = GNUNET_SERVER_client_get_user_context (client, struct ClientCtx); | 495 | client_ctx = GNUNET_SERVER_client_get_user_context (client, struct ClientCtx); |
@@ -556,12 +559,40 @@ GST_barriers_init (struct GNUNET_CONFIGURATION_Handle *cfg) | |||
556 | 559 | ||
557 | 560 | ||
558 | /** | 561 | /** |
562 | * Iterator over hash map entries. | ||
563 | * | ||
564 | * @param cls closure | ||
565 | * @param key current key code | ||
566 | * @param value value in the hash map | ||
567 | * @return #GNUNET_YES if we should continue to | ||
568 | * iterate, | ||
569 | * #GNUNET_NO if not. | ||
570 | */ | ||
571 | static int | ||
572 | barrier_destroy_iterator (void *cls, | ||
573 | const struct GNUNET_HashCode *key, | ||
574 | void *value) | ||
575 | { | ||
576 | struct Barrier *barrier = value; | ||
577 | |||
578 | GNUNET_assert (NULL != barrier); | ||
579 | cancel_wrappers (barrier); | ||
580 | remove_barrier (barrier); | ||
581 | return GNUNET_YES; | ||
582 | } | ||
583 | |||
584 | |||
585 | /** | ||
559 | * Function to stop the barrier service | 586 | * Function to stop the barrier service |
560 | */ | 587 | */ |
561 | void | 588 | void |
562 | GST_barriers_destroy () | 589 | GST_barriers_destroy () |
563 | { | 590 | { |
564 | GNUNET_assert (NULL != barrier_map); | 591 | GNUNET_assert (NULL != barrier_map); |
592 | GNUNET_assert (GNUNET_SYSERR != | ||
593 | GNUNET_CONTAINER_multihashmap_iterate (barrier_map, | ||
594 | &barrier_destroy_iterator, | ||
595 | NULL)); | ||
565 | GNUNET_CONTAINER_multihashmap_destroy (barrier_map); | 596 | GNUNET_CONTAINER_multihashmap_destroy (barrier_map); |
566 | GNUNET_assert (NULL != ctx); | 597 | GNUNET_assert (NULL != ctx); |
567 | GNUNET_SERVICE_stop (ctx); | 598 | GNUNET_SERVICE_stop (ctx); |
diff --git a/src/testbed/gnunet-service-testbed_links.c b/src/testbed/gnunet-service-testbed_links.c index d34d0c040..85a4538ef 100644 --- a/src/testbed/gnunet-service-testbed_links.c +++ b/src/testbed/gnunet-service-testbed_links.c | |||
@@ -420,51 +420,78 @@ reghost_free_iterator (void *cls, const struct GNUNET_HashCode *key, | |||
420 | 420 | ||
421 | 421 | ||
422 | /** | 422 | /** |
423 | * Kill a #Slave object | ||
424 | * | ||
425 | * @param slave the #Slave object | ||
426 | */ | ||
427 | static void | ||
428 | kill_slave (struct Slave *slave) | ||
429 | { | ||
430 | struct HostRegistration *hr_entry; | ||
431 | |||
432 | while (NULL != (hr_entry = slave->hr_dll_head)) | ||
433 | { | ||
434 | GNUNET_CONTAINER_DLL_remove (slave->hr_dll_head, slave->hr_dll_tail, | ||
435 | hr_entry); | ||
436 | GNUNET_free (hr_entry); | ||
437 | } | ||
438 | if (NULL != slave->rhandle) | ||
439 | GNUNET_TESTBED_cancel_registration (slave->rhandle); | ||
440 | GNUNET_assert (GNUNET_SYSERR != | ||
441 | GNUNET_CONTAINER_multihashmap_iterate (slave->reghost_map, | ||
442 | reghost_free_iterator, | ||
443 | slave)); | ||
444 | GNUNET_CONTAINER_multihashmap_destroy (slave->reghost_map); | ||
445 | if (NULL != slave->controller) | ||
446 | GNUNET_TESTBED_controller_disconnect (slave->controller); | ||
447 | if (NULL != slave->controller_proc) | ||
448 | { | ||
449 | LOG_DEBUG ("Stopping a slave\n"); | ||
450 | GNUNET_TESTBED_controller_kill_ (slave->controller_proc); | ||
451 | } | ||
452 | } | ||
453 | |||
454 | |||
455 | /** | ||
456 | * Destroy a #Slave object | ||
457 | * | ||
458 | * @param slave the #Slave object | ||
459 | */ | ||
460 | static void | ||
461 | destroy_slave (struct Slave *slave) | ||
462 | { | ||
463 | if (NULL != slave->controller_proc) | ||
464 | { | ||
465 | GNUNET_TESTBED_controller_destroy_ (slave->controller_proc); | ||
466 | LOG_DEBUG ("Slave stopped\n"); | ||
467 | } | ||
468 | GST_slave_list[slave->host_id] = NULL; | ||
469 | GNUNET_free (slave); | ||
470 | } | ||
471 | |||
472 | |||
473 | /** | ||
423 | * Cleans up the slave list | 474 | * Cleans up the slave list |
424 | */ | 475 | */ |
425 | void | 476 | void |
426 | GST_slave_list_clear () | 477 | GST_slave_list_clear () |
427 | { | 478 | { |
428 | struct HostRegistration *hr_entry; | 479 | struct Slave *slave; |
429 | struct GNUNET_TESTBED_ControllerProc *cproc; | ||
430 | unsigned int id; | 480 | unsigned int id; |
431 | 481 | ||
432 | for (id = 0; id < GST_slave_list_size; id++) | 482 | for (id = 0; id < GST_slave_list_size; id++) |
433 | { | 483 | { |
434 | if (NULL == GST_slave_list[id]) | 484 | slave = GST_slave_list[id]; |
485 | if (NULL == slave) | ||
435 | continue; | 486 | continue; |
436 | while (NULL != (hr_entry = GST_slave_list[id]->hr_dll_head)) | 487 | kill_slave (slave); |
437 | { | ||
438 | GNUNET_CONTAINER_DLL_remove (GST_slave_list[id]->hr_dll_head, | ||
439 | GST_slave_list[id]->hr_dll_tail, hr_entry); | ||
440 | GNUNET_free (hr_entry); | ||
441 | } | ||
442 | if (NULL != GST_slave_list[id]->rhandle) | ||
443 | GNUNET_TESTBED_cancel_registration (GST_slave_list[id]->rhandle); | ||
444 | (void) | ||
445 | GNUNET_CONTAINER_multihashmap_iterate (GST_slave_list | ||
446 | [id]->reghost_map, | ||
447 | reghost_free_iterator, | ||
448 | GST_slave_list[id]); | ||
449 | GNUNET_CONTAINER_multihashmap_destroy (GST_slave_list[id]->reghost_map); | ||
450 | if (NULL != GST_slave_list[id]->controller) | ||
451 | GNUNET_TESTBED_controller_disconnect (GST_slave_list[id]->controller); | ||
452 | if (NULL != (cproc = GST_slave_list[id]->controller_proc)) | ||
453 | { | ||
454 | LOG_DEBUG ("Stopping a slave\n"); | ||
455 | GNUNET_TESTBED_controller_kill_ (cproc); | ||
456 | } | ||
457 | } | 488 | } |
458 | for (id = 0; id < GST_slave_list_size; id++) | 489 | for (id = 0; id < GST_slave_list_size; id++) |
459 | { | 490 | { |
460 | if (NULL == GST_slave_list[id]) | 491 | slave = GST_slave_list[id]; |
492 | if (NULL == slave) | ||
461 | continue; | 493 | continue; |
462 | if (NULL != (cproc = GST_slave_list[id]->controller_proc)) | 494 | destroy_slave (slave); |
463 | { | ||
464 | GNUNET_TESTBED_controller_destroy_ (cproc); | ||
465 | LOG_DEBUG ("Slave stopped\n"); | ||
466 | } | ||
467 | GNUNET_free (GST_slave_list[id]); | ||
468 | } | 495 | } |
469 | GNUNET_free_non_null (GST_slave_list); | 496 | GNUNET_free_non_null (GST_slave_list); |
470 | GST_slave_list = NULL; | 497 | GST_slave_list = NULL; |
@@ -723,6 +750,8 @@ slave_event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
723 | GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); | 750 | GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); |
724 | lcf = event->op_cls; | 751 | lcf = event->op_cls; |
725 | GNUNET_assert (lcf->op == event->op); | 752 | GNUNET_assert (lcf->op == event->op); |
753 | GNUNET_TESTBED_operation_done (lcf->op); | ||
754 | lcf->op = NULL; | ||
726 | GNUNET_assert (FINISHED == lcf->state); | 755 | GNUNET_assert (FINISHED == lcf->state); |
727 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != lcf->timeout_task); | 756 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != lcf->timeout_task); |
728 | GNUNET_SCHEDULER_cancel (lcf->timeout_task); | 757 | GNUNET_SCHEDULER_cancel (lcf->timeout_task); |
@@ -761,8 +790,13 @@ slave_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
761 | if (GNUNET_SYSERR == status) | 790 | if (GNUNET_SYSERR == status) |
762 | { | 791 | { |
763 | slave->controller_proc = NULL; | 792 | slave->controller_proc = NULL; |
764 | GST_slave_list[slave->host_id] = NULL; | 793 | /* Stop all link controller forwarding tasks since we shutdown here anyway |
765 | GNUNET_free (slave); | 794 | and as these tasks they depend on the operation queues which are created |
795 | through GNUNET_TESTBED_controller_connect() and in kill_slave() we call | ||
796 | the destructor function GNUNET_TESTBED_controller_disconnect() */ | ||
797 | GST_free_lcfq (); | ||
798 | kill_slave (slave); | ||
799 | destroy_slave (slave); | ||
766 | slave = NULL; | 800 | slave = NULL; |
767 | LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n"); | 801 | LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n"); |
768 | GNUNET_SCHEDULER_shutdown (); /* We too shutdown */ | 802 | GNUNET_SCHEDULER_shutdown (); /* We too shutdown */ |
@@ -780,13 +814,12 @@ slave_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
780 | { | 814 | { |
781 | send_controller_link_response (lcc->client, lcc->operation_id, NULL, | 815 | send_controller_link_response (lcc->client, lcc->operation_id, NULL, |
782 | "Could not connect to delegated controller"); | 816 | "Could not connect to delegated controller"); |
783 | GNUNET_TESTBED_controller_stop (slave->controller_proc); | 817 | kill_slave (slave); |
784 | GST_slave_list[slave->host_id] = NULL; | 818 | destroy_slave (slave); |
785 | GNUNET_free (slave); | ||
786 | slave = NULL; | 819 | slave = NULL; |
787 | } | 820 | } |
788 | 821 | ||
789 | clean_lcc: | 822 | clean_lcc: |
790 | if (NULL != lcc) | 823 | if (NULL != lcc) |
791 | { | 824 | { |
792 | if (NULL != lcc->client) | 825 | if (NULL != lcc->client) |
@@ -1317,6 +1350,7 @@ void | |||
1317 | GST_free_lcfq () | 1350 | GST_free_lcfq () |
1318 | { | 1351 | { |
1319 | struct LCFContextQueue *lcfq; | 1352 | struct LCFContextQueue *lcfq; |
1353 | struct LCFContext *lcf; | ||
1320 | 1354 | ||
1321 | if (NULL != lcfq_head) | 1355 | if (NULL != lcfq_head) |
1322 | { | 1356 | { |
@@ -1329,8 +1363,13 @@ GST_free_lcfq () | |||
1329 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id); | 1363 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id); |
1330 | for (lcfq = lcfq_head; NULL != lcfq; lcfq = lcfq_head) | 1364 | for (lcfq = lcfq_head; NULL != lcfq; lcfq = lcfq_head) |
1331 | { | 1365 | { |
1332 | GNUNET_SERVER_client_drop (lcfq->lcf->client); | 1366 | lcf = lcfq->lcf; |
1333 | GNUNET_free (lcfq->lcf); | 1367 | GNUNET_SERVER_client_drop (lcf->client); |
1368 | if (NULL != lcf->op) | ||
1369 | GNUNET_TESTBED_operation_done (lcf->op); | ||
1370 | if (GNUNET_SCHEDULER_NO_TASK != lcf->timeout_task) | ||
1371 | GNUNET_SCHEDULER_cancel (lcf->timeout_task); | ||
1372 | GNUNET_free (lcf); | ||
1334 | GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq); | 1373 | GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq); |
1335 | GNUNET_free (lcfq); | 1374 | GNUNET_free (lcfq); |
1336 | } | 1375 | } |
diff --git a/src/testbed/gnunet-service-testbed_links.h b/src/testbed/gnunet-service-testbed_links.h index 428a3b070..9a2a79c04 100644 --- a/src/testbed/gnunet-service-testbed_links.h +++ b/src/testbed/gnunet-service-testbed_links.h | |||
@@ -74,16 +74,9 @@ struct Slave | |||
74 | struct GNUNET_CONTAINER_MultiHashMap *reghost_map; | 74 | struct GNUNET_CONTAINER_MultiHashMap *reghost_map; |
75 | 75 | ||
76 | /** | 76 | /** |
77 | * Operation handle for opening a lateral connection to another controller. | ||
78 | * Will be NULL if the slave controller is started by this controller | ||
79 | */ | ||
80 | struct GNUNET_TESTBED_Operation *conn_op; | ||
81 | |||
82 | /** | ||
83 | * The id of the host this controller is running on | 77 | * The id of the host this controller is running on |
84 | */ | 78 | */ |
85 | uint32_t host_id; | 79 | uint32_t host_id; |
86 | |||
87 | }; | 80 | }; |
88 | 81 | ||
89 | /** | 82 | /** |
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c index ba6e9359a..e8417c0d8 100644 --- a/src/testbed/testbed_api_hosts.c +++ b/src/testbed/testbed_api_hosts.c | |||
@@ -1008,6 +1008,7 @@ clear_msg (void *cls, int result) | |||
1008 | GNUNET_assert (NULL != cp->shandle); | 1008 | GNUNET_assert (NULL != cp->shandle); |
1009 | cp->shandle = NULL; | 1009 | cp->shandle = NULL; |
1010 | GNUNET_free (cp->msg); | 1010 | GNUNET_free (cp->msg); |
1011 | cp->msg = NULL; | ||
1011 | } | 1012 | } |
1012 | 1013 | ||
1013 | 1014 | ||
@@ -1184,6 +1185,7 @@ GNUNET_TESTBED_controller_destroy_ (struct GNUNET_TESTBED_ControllerProc *cproc) | |||
1184 | free_argv (cproc->helper_argv); | 1185 | free_argv (cproc->helper_argv); |
1185 | cproc->host->controller_started = GNUNET_NO; | 1186 | cproc->host->controller_started = GNUNET_NO; |
1186 | cproc->host->locked = GNUNET_NO; | 1187 | cproc->host->locked = GNUNET_NO; |
1188 | GNUNET_free_non_null (cproc->msg); | ||
1187 | GNUNET_free (cproc); | 1189 | GNUNET_free (cproc); |
1188 | } | 1190 | } |
1189 | 1191 | ||