summaryrefslogtreecommitdiffhomepage
path: root/contrib/package/olsrd-luci/patches
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2009-12-13 21:17:02 +0000
committerJo-Philipp Wich <jow@openwrt.org>2009-12-13 21:17:02 +0000
commit8f3bd113c39502fcbdaab28aea5f7135c9c0263a (patch)
tree7cd835ccc3fe6e9797c533da742aa2f30210e494 /contrib/package/olsrd-luci/patches
parentbbaf959e9bd5a6ec8d3e7ebf382ced9cd03c3a88 (diff)
contrib/package: fix memory leaks in olsrd 0.5.6-r7 stable
Diffstat (limited to 'contrib/package/olsrd-luci/patches')
-rw-r--r--contrib/package/olsrd-luci/patches/200-mid_memory_cleanup.patch256
1 files changed, 256 insertions, 0 deletions
diff --git a/contrib/package/olsrd-luci/patches/200-mid_memory_cleanup.patch b/contrib/package/olsrd-luci/patches/200-mid_memory_cleanup.patch
new file mode 100644
index 000000000..00b2f4c2c
--- /dev/null
+++ b/contrib/package/olsrd-luci/patches/200-mid_memory_cleanup.patch
@@ -0,0 +1,256 @@
+--- a/lib/httpinfo/src/olsrd_httpinfo.c
++++ b/lib/httpinfo/src/olsrd_httpinfo.c
+@@ -687,9 +687,16 @@
+ void
+ olsr_plugin_exit(void)
+ {
++ struct allowed_net *a, *next;
+ if (http_socket >= 0) {
+ CLOSE(http_socket);
+ }
++
++ for (a = allowed_nets; a != NULL; a = next) {
++ next = a->next;
++
++ free(a);
++ }
+ }
+
+ static void
+--- a/src/interfaces.h
++++ b/src/interfaces.h
+@@ -187,6 +187,7 @@
+ extern struct interface *ifnet;
+
+ int ifinit(void);
++void olsr_delete_interfaces(void);
+
+ void run_ifchg_cbs(struct interface *, int);
+
+--- a/src/linux/kernel_routes.c
++++ b/src/linux/kernel_routes.c
+@@ -85,6 +85,8 @@
+ OLSR_PRINTF(1,"could not create rtnetlink socket! %d",sock);
+ }
+ else {
++ memset(&addr, 0, sizeof(addr));
++
+ addr.nl_family = AF_NETLINK;
+ addr.nl_pid = 0; //kernel will assign appropiate number instead of pid (which is already used by primaray rtnetlink socket to add/delete routes)
+ addr.nl_groups = rtnl_mgrp;
+--- a/src/main.c
++++ b/src/main.c
+@@ -57,6 +57,7 @@
+ #include "net_os.h"
+ #include "build_msg.h"
+ #include "net_olsr.h"
++#include "mid_set.h"
+
+ #if LINUX_POLICY_ROUTING
+ #include <linux/types.h>
+@@ -526,6 +527,7 @@
+ #endif
+ {
+ struct interface *ifn;
++ int exit_value;
+
+ OLSR_PRINTF(1, "Received signal %d - shutting down\n", (int)signo);
+
+@@ -542,6 +544,12 @@
+
+ olsr_delete_all_kernel_routes();
+
++ olsr_delete_all_tc_entries();
++
++ olsr_delete_all_mid_entries();
++
++ olsr_destroy_parser();
++
+ OLSR_PRINTF(1, "Closing sockets...\n");
+
+ /* front-end IPC socket */
+@@ -551,7 +559,6 @@
+ }
+ #endif /* SVEN_OLA_UNBLOAT */
+
+- /* OLSR sockets */
+ for (ifn = ifnet; ifn; ifn = ifn->int_next)
+ close(ifn->olsr_socket);
+
+@@ -581,13 +588,17 @@
+ #endif
+
+ /* Free cookies and memory pools attached. */
++ OLSR_PRINTF(0, "Free all memory...\n");
+ olsr_delete_all_cookies();
+
+ olsr_syslog(OLSR_LOG_INFO, "%s stopped", olsrd_version);
+
+ OLSR_PRINTF(1, "\n <<<< %s - terminating >>>>\n http://www.olsr.org\n", olsrd_version);
+
+- exit(olsr_cnf->exit_value);
++ exit_value = olsr_cnf->exit_value;
++ free (olsr_cnf);
++
++ exit(exit_value);
+ }
+
+ /**
+--- a/src/mid_set.c
++++ b/src/mid_set.c
+@@ -38,6 +38,7 @@
+ * the copyright holders.
+ *
+ */
++#include <assert.h>
+
+ #include "ipcalc.h"
+ #include "defs.h"
+@@ -79,6 +80,15 @@
+ return 1;
+ }
+
++void olsr_delete_all_mid_entries(void) {
++ int hash;
++
++ for (hash = 0; hash < HASHSIZE; hash++) {
++ while (mid_set[hash].next != &mid_set[hash]) {
++ olsr_delete_mid_entry(mid_set[hash].next);
++ }
++ }
++}
+ /**
+ * Wrapper for the timer callback.
+ */
+@@ -124,10 +134,10 @@
+ *
+ * @param m_addr the main address of the node
+ * @param alias the alias address to insert
+- * @return nada
++ * @return false if mid_address is unnecessary, true otherwise
+ */
+
+-void
++static bool
+ insert_mid_tuple(union olsr_ip_addr *m_addr, struct mid_address *alias, olsr_reltime vtime)
+ {
+ struct mid_entry *tmp;
+@@ -147,9 +157,8 @@
+ /* Check if alias is already registered with m_addr */
+ registered_m_addr = mid_lookup_main_addr(&alias->alias);
+ if (registered_m_addr != NULL && ipequal(registered_m_addr, m_addr)) {
+-
+ /* Alias is already registered with main address. Nothing to do here. */
+- return;
++ return false;
+ }
+
+ /*
+@@ -223,6 +232,7 @@
+ }
+ tmp_adr = tmp_adr->next_alias;
+ }
++ return true;
+ }
+
+ /**
+@@ -284,7 +294,9 @@
+ }
+ }
+
+- insert_mid_tuple(main_add, adr, vtime);
++ if (!insert_mid_tuple(main_add, adr, vtime)) {
++ free(adr);
++ }
+
+ /*
+ *Recalculate topology
+--- a/src/mid_set.h
++++ b/src/mid_set.h
+@@ -75,7 +75,7 @@
+ struct mid_alias;
+
+ int olsr_init_mid_set(void);
+-void insert_mid_tuple(union olsr_ip_addr *, struct mid_address *, olsr_reltime);
++void olsr_delete_all_mid_entries(void);
+ void insert_mid_alias(union olsr_ip_addr *, const union olsr_ip_addr *, olsr_reltime);
+ union olsr_ip_addr *mid_lookup_main_addr(const union olsr_ip_addr *);
+ struct mid_address *mid_lookup_aliases(const union olsr_ip_addr *);
+--- a/src/parser.c
++++ b/src/parser.c
+@@ -104,6 +104,26 @@
+ }
+
+ void
++olsr_destroy_parser(void) {
++ struct parse_function_entry *pe, *pe_next;
++ struct preprocessor_function_entry *ppe, *ppe_next;
++ struct packetparser_function_entry *pae, *pae_next;
++
++ for (pe = parse_functions; pe; pe = pe_next) {
++ pe_next = pe->next;
++ free (pe);
++ }
++ for (ppe = preprocessor_functions; ppe; ppe = ppe_next) {
++ ppe_next = ppe->next;
++ free (ppe);
++ }
++ for (pae = packetparser_functions; pae; pae = pae_next) {
++ pae_next = pae->next;
++ free(pae);
++ }
++}
++
++void
+ olsr_parser_add_function(parse_function * function, uint32_t type)
+ {
+ struct parse_function_entry *new_entry;
+--- a/src/parser.h
++++ b/src/parser.h
+@@ -74,6 +74,8 @@
+
+ void olsr_init_parser(void);
+
++void olsr_destroy_parser(void);
++
+ void olsr_input(int);
+
+ void olsr_input_hostemu(int);
+--- a/src/scheduler.c
++++ b/src/scheduler.c
+@@ -40,6 +40,8 @@
+ *
+ */
+
++#include <assert.h>
++
+ #include "defs.h"
+ #include "scheduler.h"
+ #include "log.h"
+--- a/src/tc_set.c
++++ b/src/tc_set.c
+@@ -205,6 +205,14 @@
+ tc_myself = olsr_add_tc_entry(&olsr_cnf->main_addr);
+ }
+
++void olsr_delete_all_tc_entries(void) {
++ struct tc_entry *tc;
++
++ OLSR_FOR_ALL_TC_ENTRIES(tc) {
++ olsr_delete_tc_entry(tc);
++ } OLSR_FOR_ALL_TC_ENTRIES_END(tc)
++}
++
+ /**
+ * The main ip address has changed.
+ * Do the needful.
+--- a/src/tc_set.h
++++ b/src/tc_set.h
+@@ -142,6 +142,7 @@
+ extern struct tc_entry *tc_myself;
+
+ void olsr_init_tc(void);
++void olsr_delete_all_tc_entries(void);
+ void olsr_change_myself_tc(void);
+ void olsr_print_tc_table(void);
+ void olsr_time_out_tc_set(void);