fix networker hickup
authorWilfried Goesgens <dothebart@citadel.org>
Fri, 1 Jun 2012 18:55:57 +0000 (20:55 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Fri, 1 Jun 2012 18:55:57 +0000 (20:55 +0200)
  - 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.

citadel/modules/network/netconfig.h
citadel/modules/network/serv_netconfig.c
citadel/modules/network/serv_network.c

index 37e1e0c3e874bb8f48d370c72b5ea9242a99ea70..9d71d9fb4dbf1c3c8266fc8006fc2d9ff7ef785d 100644 (file)
@@ -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);
index 3902c0eb3ab8919934b104e85b1d774bce9fc001..9d1e6bc742bad69962b743a5eeb8f5488aa6cc53 100644 (file)
@@ -116,10 +116,13 @@ NetMap *read_network_map(void) {
        /* Use the string tokenizer to grab one line at a time */
        for (i=0; i<num_tokens(serialized_map, '\n'); ++i) {
                extract_token(buf, serialized_map, i, '\n', sizeof buf);
+
                nmptr = (NetMap *) malloc(sizeof(NetMap));
+
                extract_token(nmptr->nodename, 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);
index 7ac84729c331241d482c5d63b5232a30c6be600d..7c8c47047991de20dffb8cafa34f92e56b636bf7 100644 (file)
@@ -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");