diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-07-15 09:22:28 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-07-15 09:22:28 +0000 |
commit | a85848d1c6686713c0c977868eba2d5fe4fa322f (patch) | |
tree | 9d3b14d3dc43e669492eff0e842708d182c15cf6 /src/transport/plugin_transport_tcp.c | |
parent | 3b1199eb8f4a3319a13d34878a956f16c66a5b19 (diff) | |
download | gnunet-a85848d1c6686713c0c977868eba2d5fe4fa322f.tar.gz gnunet-a85848d1c6686713c0c977868eba2d5fe4fa322f.zip |
while running transport: valgrind showed memory leak due to not removed resolution processes
storing pretty printer requests and removing them after timeout
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index b124fc618..be1076ea1 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -1564,10 +1564,40 @@ tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | |||
1564 | 1564 | ||
1565 | 1565 | ||
1566 | /** | 1566 | /** |
1567 | * Running pretty printers: head | ||
1568 | */ | ||
1569 | static struct PrettyPrinterContext *ppc_dll_head; | ||
1570 | |||
1571 | /** | ||
1572 | * Running pretty printers: tail | ||
1573 | */ | ||
1574 | static struct PrettyPrinterContext *ppc_dll_tail; | ||
1575 | |||
1576 | /** | ||
1567 | * Context for address to string conversion. | 1577 | * Context for address to string conversion. |
1568 | */ | 1578 | */ |
1569 | struct PrettyPrinterContext | 1579 | struct PrettyPrinterContext |
1570 | { | 1580 | { |
1581 | /** | ||
1582 | * DLL | ||
1583 | */ | ||
1584 | struct PrettyPrinterContext *next; | ||
1585 | |||
1586 | /** | ||
1587 | * DLL | ||
1588 | */ | ||
1589 | struct PrettyPrinterContext *prev; | ||
1590 | |||
1591 | /** | ||
1592 | * Timeout task | ||
1593 | */ | ||
1594 | GNUNET_SCHEDULER_TaskIdentifier timeout_task; | ||
1595 | |||
1596 | /** | ||
1597 | * Resolver handle | ||
1598 | */ | ||
1599 | struct GNUNET_RESOLVER_RequestHandle *resolver_handle; | ||
1600 | |||
1571 | /** | 1601 | /** |
1572 | * Function to call with the result. | 1602 | * Function to call with the result. |
1573 | */ | 1603 | */ |
@@ -1595,6 +1625,23 @@ struct PrettyPrinterContext | |||
1595 | }; | 1625 | }; |
1596 | 1626 | ||
1597 | 1627 | ||
1628 | void | ||
1629 | ppc_cancel_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1630 | { | ||
1631 | struct PrettyPrinterContext *ppc = cls; | ||
1632 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "PPC %p was not removed!\n", ppc); | ||
1633 | ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
1634 | if (NULL != ppc->resolver_handle) | ||
1635 | { | ||
1636 | GNUNET_RESOLVER_request_cancel (ppc->resolver_handle); | ||
1637 | ppc->resolver_handle = NULL; | ||
1638 | } | ||
1639 | |||
1640 | GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, ppc); | ||
1641 | GNUNET_free (ppc); | ||
1642 | } | ||
1643 | |||
1644 | |||
1598 | /** | 1645 | /** |
1599 | * Append our port and forward the result. | 1646 | * Append our port and forward the result. |
1600 | * | 1647 | * |
@@ -1605,14 +1652,31 @@ static void | |||
1605 | append_port (void *cls, const char *hostname) | 1652 | append_port (void *cls, const char *hostname) |
1606 | { | 1653 | { |
1607 | struct PrettyPrinterContext *ppc = cls; | 1654 | struct PrettyPrinterContext *ppc = cls; |
1655 | struct PrettyPrinterContext *cur; | ||
1608 | char *ret; | 1656 | char *ret; |
1609 | 1657 | ||
1610 | if (hostname == NULL) | 1658 | if (hostname == NULL) |
1611 | { | 1659 | { |
1612 | ppc->asc (ppc->asc_cls, NULL); | 1660 | ppc->asc (ppc->asc_cls, NULL); |
1661 | GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, ppc); | ||
1662 | GNUNET_SCHEDULER_cancel (ppc->timeout_task); | ||
1663 | ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
1664 | ppc->resolver_handle = NULL; | ||
1665 | /* GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "PPC %p was removed!\n", ppc); */ | ||
1613 | GNUNET_free (ppc); | 1666 | GNUNET_free (ppc); |
1614 | return; | 1667 | return; |
1615 | } | 1668 | } |
1669 | for (cur = ppc_dll_head; (NULL != cur); cur = cur->next) | ||
1670 | { | ||
1671 | if (cur == ppc) | ||
1672 | break; | ||
1673 | } | ||
1674 | if (NULL == cur) | ||
1675 | { | ||
1676 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid callback for PPC %p \n", ppc); | ||
1677 | return; | ||
1678 | } | ||
1679 | |||
1616 | if (GNUNET_YES == ppc->ipv6) | 1680 | if (GNUNET_YES == ppc->ipv6) |
1617 | GNUNET_asprintf (&ret, "%s.%u.[%s]:%d", PLUGIN_NAME, ppc->options, hostname, ppc->port); | 1681 | GNUNET_asprintf (&ret, "%s.%u.[%s]:%d", PLUGIN_NAME, ppc->options, hostname, ppc->port); |
1618 | else | 1682 | else |
@@ -1702,7 +1766,12 @@ tcp_plugin_address_pretty_printer (void *cls, const char *type, | |||
1702 | ppc->asc_cls = asc_cls; | 1766 | ppc->asc_cls = asc_cls; |
1703 | ppc->port = port; | 1767 | ppc->port = port; |
1704 | ppc->options = options; | 1768 | ppc->options = options; |
1705 | GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc); | 1769 | ppc->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(timeout, 2), |
1770 | &ppc_cancel_task, ppc); | ||
1771 | GNUNET_CONTAINER_DLL_insert (ppc_dll_head, ppc_dll_tail, ppc); | ||
1772 | /* GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "PPC %p was created!\n", ppc); */ | ||
1773 | ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, | ||
1774 | timeout, &append_port, ppc); | ||
1706 | } | 1775 | } |
1707 | 1776 | ||
1708 | 1777 | ||
@@ -2599,6 +2668,8 @@ libgnunet_plugin_transport_tcp_done (void *cls) | |||
2599 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; | 2668 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; |
2600 | struct Plugin *plugin = api->cls; | 2669 | struct Plugin *plugin = api->cls; |
2601 | struct TCPProbeContext *tcp_probe; | 2670 | struct TCPProbeContext *tcp_probe; |
2671 | struct PrettyPrinterContext *cur; | ||
2672 | struct PrettyPrinterContext *next; | ||
2602 | 2673 | ||
2603 | if (NULL == plugin) | 2674 | if (NULL == plugin) |
2604 | { | 2675 | { |
@@ -2612,6 +2683,17 @@ libgnunet_plugin_transport_tcp_done (void *cls) | |||
2612 | /* Removing leftover NAT sessions */ | 2683 | /* Removing leftover NAT sessions */ |
2613 | GNUNET_CONTAINER_multihashmap_iterate(plugin->nat_wait_conns, &session_disconnect_it, NULL); | 2684 | GNUNET_CONTAINER_multihashmap_iterate(plugin->nat_wait_conns, &session_disconnect_it, NULL); |
2614 | 2685 | ||
2686 | next = ppc_dll_head; | ||
2687 | for (cur = next; NULL != cur; cur = next) | ||
2688 | { | ||
2689 | next = cur->next; | ||
2690 | GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, cur); | ||
2691 | GNUNET_RESOLVER_request_cancel (cur->resolver_handle); | ||
2692 | GNUNET_SCHEDULER_cancel (cur->timeout_task); | ||
2693 | GNUNET_free (cur); | ||
2694 | GNUNET_break (0); | ||
2695 | } | ||
2696 | |||
2615 | if (plugin->service != NULL) | 2697 | if (plugin->service != NULL) |
2616 | GNUNET_SERVICE_stop (plugin->service); | 2698 | GNUNET_SERVICE_stop (plugin->service); |
2617 | else | 2699 | else |