From: Wilfried Goesgens Date: Fri, 1 Jun 2012 18:55:57 +0000 (+0200) Subject: fix networker hickup X-Git-Tag: v8.12~40 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=f83224ff00fdeda026d136863a72c945ef8536e4 fix networker hickup - refrain from freeing pointers in functions that don't get double pointers and NULL them afterwards - call network_consolidate_spoolout () before writing & free'ing the network. --- diff --git a/citadel/modules/network/netconfig.h b/citadel/modules/network/netconfig.h index 37e1e0c3e..9d71d9fb4 100644 --- a/citadel/modules/network/netconfig.h +++ b/citadel/modules/network/netconfig.h @@ -9,5 +9,5 @@ struct NetMap { char* load_working_ignetcfg(void); NetMap *read_network_map(void); -void write_network_map(NetMap *the_netmap, int netmap_changed); +void write_and_free_network_map(NetMap **the_netmap, int netmap_changed); int is_valid_node(char *nexthop, char *secret, char *node, char *working_ignetcfg, NetMap *the_netmap); diff --git a/citadel/modules/network/serv_netconfig.c b/citadel/modules/network/serv_netconfig.c index 3902c0eb3..9d1e6bc74 100644 --- a/citadel/modules/network/serv_netconfig.c +++ b/citadel/modules/network/serv_netconfig.c @@ -116,10 +116,13 @@ NetMap *read_network_map(void) { /* Use the string tokenizer to grab one line at a time */ for (i=0; inodename, buf, 0, '|', sizeof nmptr->nodename); nmptr->lastcontact = extract_long(buf, 1); extract_token(nmptr->nexthop, buf, 2, '|', sizeof nmptr->nexthop); + nmptr->next = the_netmap; the_netmap = nmptr; } @@ -132,16 +135,16 @@ NetMap *read_network_map(void) { /* * Write the network map from memory back to the configuration file. */ -void write_network_map(NetMap *the_netmap, int netmap_changed) { +void write_and_free_network_map(NetMap **the_netmap, int netmap_changed) +{ char *serialized_map = NULL; NetMap *nmptr; - if (netmap_changed) { serialized_map = strdup(""); - if (the_netmap != NULL) { - for (nmptr = the_netmap; nmptr != NULL; nmptr = nmptr->next) { + if (*the_netmap != NULL) { + for (nmptr = *the_netmap; nmptr != NULL; nmptr = nmptr->next) { serialized_map = realloc(serialized_map, (strlen(serialized_map)+SIZ) ); if (!IsEmptyStr(nmptr->nodename)) { @@ -160,10 +163,10 @@ void write_network_map(NetMap *the_netmap, int netmap_changed) { } /* Now free the list */ - while (the_netmap != NULL) { - nmptr = the_netmap->next; - free(the_netmap); - the_netmap = nmptr; + while (*the_netmap != NULL) { + nmptr = (*the_netmap)->next; + free(*the_netmap); + *the_netmap = nmptr; } } @@ -368,9 +371,9 @@ void cmd_netp(char *cmdbuf) char pass[256]; int v; - char secret[256]; - char nexthop[256]; - char err_buf[SIZ]; + char secret[256] = ""; + char nexthop[256] = ""; + char err_buf[SIZ] = ""; /* Authenticate */ nodelen = extract_token(node, cmdbuf, 0, '|', sizeof node); diff --git a/citadel/modules/network/serv_network.c b/citadel/modules/network/serv_network.c index 7ac84729c..7c8c47047 100644 --- a/citadel/modules/network/serv_network.c +++ b/citadel/modules/network/serv_network.c @@ -590,13 +590,14 @@ void network_do_queue(void) { &netmap_changed); } - /* Save the network map back to disk */ - write_network_map(the_netmap, netmap_changed); - /* Free the filter list in memory */ free_netfilter_list(); network_consolidate_spoolout(working_ignetcfg, the_netmap); + + /* Save the network map back to disk */ + write_and_free_network_map(&the_netmap, netmap_changed); + free(working_ignetcfg); syslog(LOG_DEBUG, "network: queue run completed\n");