Fix memory leaks in the networker
[citadel.git] / citadel / modules / network / serv_netmail.c
index 6b7494bb7ea991be1e8a94a8d3e3362ba56642b1..90e4e6891f41f272fca90b115f2052dd700b1d1d 100644 (file)
@@ -88,6 +88,8 @@
 
 #include "context.h"
 #include "netconfig.h"
+#include "netspool.h"
+#include "netmail.h"
 #include "ctdl_module.h"
 
 
@@ -255,7 +257,9 @@ void network_deliver_list(struct CtdlMessage *msg, SpoolControl *sc) {
 /*
  * Spools out one message from the list.
  */
-void network_spool_msg(long msgnum, void *userdata) {
+void network_spool_msg(long msgnum, 
+                      void *userdata)
+{
        SpoolControl *sc;
        int i;
        char *newpath = NULL;
@@ -287,6 +291,8 @@ void network_spool_msg(long msgnum, void *userdata) {
                        char *pCh;
                        StrBuf *Subject, *FlatSubject;
 
+                       if (msg->cm_fields['K'] != NULL)
+                               free(msg->cm_fields['K']);
                        if (msg->cm_fields['V'] == NULL){
                                /* local message, no enVelope */
                                StrBuf *Buf;
@@ -427,7 +433,12 @@ void network_spool_msg(long msgnum, void *userdata) {
                                if (!strcasecmp(msg->cm_fields['N'], config.c_nodename)) {
                                        ok_to_participate = 1;
                                }
-                               if (is_valid_node(NULL, NULL, msg->cm_fields['N']) == 0) {
+                               if (is_valid_node(NULL, 
+                                                 NULL, 
+                                                 msg->cm_fields['N'], 
+                                                 sc->working_ignetcfg, 
+                                                 sc->the_netmap) == 0)
+                               {
                                        ok_to_participate = 1;
                                }
                        }
@@ -455,7 +466,7 @@ void network_spool_msg(long msgnum, void *userdata) {
                                 */
                                for (nptr = sc->participates; nptr != NULL; nptr = nptr->next) {
 
-                                       if (msg->cm_fields['R'] == NULL) {
+                                       if (msg->cm_fields['R'] != NULL) {
                                                free(msg->cm_fields['R']);
                                        }
                                        msg->cm_fields['R'] = strdup(nptr->name);
@@ -509,7 +520,12 @@ void network_spool_msg(long msgnum, void *userdata) {
                        send = 1;
 
                        /* Check for valid node name */
-                       if (is_valid_node(NULL, NULL, mptr->remote_nodename) != 0) {
+                       if (is_valid_node(NULL, 
+                                         NULL, 
+                                         mptr->remote_nodename, 
+                                         sc->working_ignetcfg, 
+                                         sc->the_netmap) != 0)
+                       {
                                syslog(LOG_ERR, "Invalid node <%s>\n", mptr->remote_nodename);
                                send = 0;
                        }