diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-05-28 13:38:58 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-05-28 13:38:58 +0000 |
commit | 5b42c8e805cf5a60fc509c4016c212c3fe9ba806 (patch) | |
tree | 1ef0fea71e7fc31e4e869bc85131c5381f53f62e /src/vpn | |
parent | fc1b9d4caffabba3411a27f62f9ea309a2cf8edc (diff) | |
download | gnunet-5b42c8e805cf5a60fc509c4016c212c3fe9ba806.tar.gz gnunet-5b42c8e805cf5a60fc509c4016c212c3fe9ba806.zip |
-simplify logic, fix double free
Diffstat (limited to 'src/vpn')
-rw-r--r-- | src/vpn/gnunet-helper-vpn.c | 7 | ||||
-rw-r--r-- | src/vpn/gnunet-service-vpn.c | 53 |
2 files changed, 17 insertions, 43 deletions
diff --git a/src/vpn/gnunet-helper-vpn.c b/src/vpn/gnunet-helper-vpn.c index 521aba0f8..0ac398d53 100644 --- a/src/vpn/gnunet-helper-vpn.c +++ b/src/vpn/gnunet-helper-vpn.c | |||
@@ -50,7 +50,7 @@ | |||
50 | * Should we print (interesting|debug) messages that can happen during | 50 | * Should we print (interesting|debug) messages that can happen during |
51 | * normal operation? | 51 | * normal operation? |
52 | */ | 52 | */ |
53 | #define DEBUG GNUNET_NO | 53 | #define DEBUG GNUNET_YES |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Maximum size of a GNUnet message (GNUNET_SERVER_MAX_MESSAGE_SIZE) | 56 | * Maximum size of a GNUnet message (GNUNET_SERVER_MAX_MESSAGE_SIZE) |
@@ -364,7 +364,7 @@ run (int fd_tun) | |||
364 | tests fail. With '||' the tests pass, but this process | 364 | tests fail. With '||' the tests pass, but this process |
365 | keeps running --- but only for the 'GNS' test --- | 365 | keeps running --- but only for the 'GNS' test --- |
366 | even though the stdout is closed :-(. Very confusing. */ | 366 | even though the stdout is closed :-(. Very confusing. */ |
367 | while ((1 == read_open) || (1 == write_open)) | 367 | while ((1 == read_open) && (1 == write_open)) |
368 | { | 368 | { |
369 | FD_ZERO (&fds_w); | 369 | FD_ZERO (&fds_w); |
370 | FD_ZERO (&fds_r); | 370 | FD_ZERO (&fds_r); |
@@ -547,6 +547,7 @@ PROCESS_BUFFER: | |||
547 | } | 547 | } |
548 | } | 548 | } |
549 | } | 549 | } |
550 | fprintf (stderr, "Existing select() loop\n"); | ||
550 | } | 551 | } |
551 | 552 | ||
552 | 553 | ||
@@ -568,6 +569,8 @@ main (int argc, char **argv) | |||
568 | int fd_tun; | 569 | int fd_tun; |
569 | int global_ret; | 570 | int global_ret; |
570 | 571 | ||
572 | fprintf (stderr, | ||
573 | "VPN helper running!\n"); | ||
571 | if (6 != argc) | 574 | if (6 != argc) |
572 | { | 575 | { |
573 | fprintf (stderr, "Fatal: must supply 5 arguments!\n"); | 576 | fprintf (stderr, "Fatal: must supply 5 arguments!\n"); |
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c index 62d6b3e23..2835c1956 100644 --- a/src/vpn/gnunet-service-vpn.c +++ b/src/vpn/gnunet-service-vpn.c | |||
@@ -84,11 +84,6 @@ struct DestinationChannel | |||
84 | struct DestinationEntry *destination; | 84 | struct DestinationEntry *destination; |
85 | 85 | ||
86 | /** | 86 | /** |
87 | * Pre-allocated channel for this destination, or NULL for none. | ||
88 | */ | ||
89 | struct ChannelState *ts; | ||
90 | |||
91 | /** | ||
92 | * Destination port this channel state is used for. | 87 | * Destination port this channel state is used for. |
93 | */ | 88 | */ |
94 | uint16_t destination_port; | 89 | uint16_t destination_port; |
@@ -247,12 +242,6 @@ struct ChannelState | |||
247 | struct ChannelMessageQueueEntry *tmq_tail; | 242 | struct ChannelMessageQueueEntry *tmq_tail; |
248 | 243 | ||
249 | /** | 244 | /** |
250 | * Destination entry that has a pointer to this channel state; | ||
251 | * NULL if this channel state is in the channel map. | ||
252 | */ | ||
253 | struct DestinationChannel *destination_container; | ||
254 | |||
255 | /** | ||
256 | * Destination to which this channel leads. Note that | 245 | * Destination to which this channel leads. Note that |
257 | * this struct is NOT in the destination_map (but a | 246 | * this struct is NOT in the destination_map (but a |
258 | * local copy) and that the 'heap_node' should always | 247 | * local copy) and that the 'heap_node' should always |
@@ -552,6 +541,17 @@ free_channel_state (struct ChannelState *ts) | |||
552 | 541 | ||
553 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 542 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
554 | "Cleaning up channel state\n"); | 543 | "Cleaning up channel state\n"); |
544 | if (NULL != ts->th) | ||
545 | { | ||
546 | GNUNET_CADET_notify_transmit_ready_cancel (ts->th); | ||
547 | ts->th = NULL; | ||
548 | } | ||
549 | if (NULL != (channel = ts->channel)) | ||
550 | { | ||
551 | ts->channel = NULL; | ||
552 | GNUNET_CADET_channel_destroy (channel); | ||
553 | return; | ||
554 | } | ||
555 | GNUNET_STATISTICS_update (stats, | 555 | GNUNET_STATISTICS_update (stats, |
556 | gettext_noop ("# Active channels"), | 556 | gettext_noop ("# Active channels"), |
557 | -1, GNUNET_NO); | 557 | -1, GNUNET_NO); |
@@ -564,17 +564,7 @@ free_channel_state (struct ChannelState *ts) | |||
564 | GNUNET_free (tnq); | 564 | GNUNET_free (tnq); |
565 | } | 565 | } |
566 | GNUNET_assert (0 == ts->tmq_length); | 566 | GNUNET_assert (0 == ts->tmq_length); |
567 | if (NULL != ts->th) | ||
568 | { | ||
569 | GNUNET_CADET_notify_transmit_ready_cancel (ts->th); | ||
570 | ts->th = NULL; | ||
571 | } | ||
572 | GNUNET_assert (NULL == ts->destination.heap_node); | 567 | GNUNET_assert (NULL == ts->destination.heap_node); |
573 | if (NULL != (channel = ts->channel)) | ||
574 | { | ||
575 | ts->channel = NULL; | ||
576 | GNUNET_CADET_channel_destroy (channel); | ||
577 | } | ||
578 | if (NULL != ts->search) | 568 | if (NULL != ts->search) |
579 | { | 569 | { |
580 | GNUNET_REGEX_search_cancel (ts->search); | 570 | GNUNET_REGEX_search_cancel (ts->search); |
@@ -596,12 +586,6 @@ free_channel_state (struct ChannelState *ts) | |||
596 | &key, | 586 | &key, |
597 | ts)); | 587 | ts)); |
598 | } | 588 | } |
599 | if (NULL != ts->destination_container) | ||
600 | { | ||
601 | GNUNET_assert (ts == ts->destination_container->ts); | ||
602 | ts->destination_container->ts = NULL; | ||
603 | ts->destination_container = NULL; | ||
604 | } | ||
605 | GNUNET_free (ts); | 589 | GNUNET_free (ts); |
606 | } | 590 | } |
607 | 591 | ||
@@ -796,7 +780,6 @@ create_channel_to_destination (struct DestinationChannel *dt, | |||
796 | GNUNET_STATISTICS_update (stats, | 780 | GNUNET_STATISTICS_update (stats, |
797 | gettext_noop ("# Cadet channels created"), | 781 | gettext_noop ("# Cadet channels created"), |
798 | 1, GNUNET_NO); | 782 | 1, GNUNET_NO); |
799 | GNUNET_assert (NULL == dt->ts); | ||
800 | switch (client_af) | 783 | switch (client_af) |
801 | { | 784 | { |
802 | case AF_INET: | 785 | case AF_INET: |
@@ -813,8 +796,6 @@ create_channel_to_destination (struct DestinationChannel *dt, | |||
813 | ts->af = client_af; | 796 | ts->af = client_af; |
814 | ts->destination = *dt->destination; | 797 | ts->destination = *dt->destination; |
815 | ts->destination.heap_node = NULL; /* copy is NOT in destination heap */ | 798 | ts->destination.heap_node = NULL; /* copy is NOT in destination heap */ |
816 | dt->ts = ts; | ||
817 | ts->destination_container = dt; /* we are referenced from dt */ | ||
818 | if (dt->destination->is_service) | 799 | if (dt->destination->is_service) |
819 | { | 800 | { |
820 | ts->channel = GNUNET_CADET_channel_create (cadet_handle, | 801 | ts->channel = GNUNET_CADET_channel_create (cadet_handle, |
@@ -1102,14 +1083,9 @@ route_packet (struct DestinationEntry *destination, | |||
1102 | GNUNET_h2s (&key)); | 1083 | GNUNET_h2s (&key)); |
1103 | /* need to either use the existing channel from the destination (if still | 1084 | /* need to either use the existing channel from the destination (if still |
1104 | available) or create a fresh one */ | 1085 | available) or create a fresh one */ |
1105 | if (NULL == dt->ts) | 1086 | ts = create_channel_to_destination (dt, af); |
1106 | ts = create_channel_to_destination (dt, af); | ||
1107 | else | ||
1108 | ts = dt->ts; | ||
1109 | if (NULL == ts) | 1087 | if (NULL == ts) |
1110 | return; | 1088 | return; |
1111 | dt->ts = NULL; | ||
1112 | ts->destination_container = NULL; /* no longer 'contained' */ | ||
1113 | /* now bind existing "unbound" channel to our IP/port tuple */ | 1089 | /* now bind existing "unbound" channel to our IP/port tuple */ |
1114 | ts->protocol = protocol; | 1090 | ts->protocol = protocol; |
1115 | ts->af = af; | 1091 | ts->af = af; |
@@ -2519,11 +2495,6 @@ free_destination_entry (struct DestinationEntry *de) | |||
2519 | GNUNET_CONTAINER_DLL_remove (de->dt_head, | 2495 | GNUNET_CONTAINER_DLL_remove (de->dt_head, |
2520 | de->dt_tail, | 2496 | de->dt_tail, |
2521 | dt); | 2497 | dt); |
2522 | if (NULL != dt->ts) | ||
2523 | { | ||
2524 | free_channel_state (dt->ts); | ||
2525 | GNUNET_assert (NULL == dt->ts); | ||
2526 | } | ||
2527 | GNUNET_free (dt); | 2498 | GNUNET_free (dt); |
2528 | } | 2499 | } |
2529 | if (NULL != de->heap_node) | 2500 | if (NULL != de->heap_node) |