]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Code cleaning (fix memory leak within subafn)
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 27 Jun 2025 20:15:42 +0000 (16:15 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 27 Jun 2025 20:15:42 +0000 (16:15 -0400)
Makefile.dbg
lib/lvleml.c
lib/lvleml.h
lib/subafn.c
lib/unitls.c

index 2a71ccd7bf5fed92307c4d3fe0710a6d73544ce3..55e3a791dbfb5ccb19586d4a356ba4e28601cafc 100644 (file)
@@ -82,6 +82,7 @@ onesortr:  debug
 #a full complete test
 
 restart        :  killall dosortr dorcvr
+          @ echo "Restart completed"
 
 actions        :  debug newtest restart
 
index 509e135df6e150b30dd52ebc28da18dc630b2ed2..6812c2eebf9aaa370a06d7a130572cb46eb6dcba 100644 (file)
 #include       "geseml.h"
 #include       "lvleml.h"
 
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
+/*     Procedure to manage curent SMTP session data    */
+/*      within contact.                                 */
+/*                                                      */
+/********************************************************/
+static void getsessid(CONTYP *contact)
+
+{
+if (contact!=(CONTYP *)0) {
+  contact->session=sql_freeses(contact->session);
+  contact->session=(SESTYP *)calloc(1,sizeof(SESTYP));
+  contact->session->sessid=eml_getcursesid(contact->mainsesid,contact->numreset);
+  }
+}
 /*
 ^L
 */
@@ -44,7 +62,7 @@ if (contact!=(CONTYP *)0) {
   contact->recipients=(RCPTYP **)rou_freelist((void **)contact->recipients,
                                               (genfree_t)eml_freerecipient);
   contact->mailfrom=rou_freestr(contact->mailfrom);
-  contact->cursesid=rou_freestr(contact->cursesid);
+  contact->session=sql_freeses(contact->session);
   contact->mainsesid=rou_freestr(contact->mainsesid);
   contact->fqdn=rou_freestr(contact->fqdn);
   contact->peername=rou_freestr(contact->peername);
@@ -243,7 +261,7 @@ while (proceed==true) {
       break;
     case 3      :       //Inserting ID information
       (void) fprintf(data,"\tid <%s@%s>;\n",
-                          contact->cursesid,contact->locname);
+                          contact->session->sessid,contact->locname);
       break;
     case 4      :       //date information
       (void) fprintf(data,"\t%s\n",rou_ascsysstamp(curtime));
@@ -377,8 +395,8 @@ proceed=true;
 while (proceed==true) {
   switch (phase) {
     case 0      :       //is contact good
-      if (contact==(CONTYP *)0) {
-        (void) rou_alert(0,"%s contact pointer is NULL (bug?)",OPEP);
+      if ((contact==(CONTYP *)0)||(contact->session==(SESTYP *)0)) {
+        (void) rou_alert(0,"%s contact pointer or session is NULL (bug?)",OPEP);
         phase=999;
         }
       break;
@@ -387,16 +405,16 @@ while (proceed==true) {
         phase=999;      //No recipient!
       break;
     case 2      :       //creating the count file
-      if ((qfile=eml_createqfile(contact->cursesid,EXTCNT))==(FILE *)0) {
+      if ((qfile=eml_createqfile(contact->session->sessid,EXTCNT))==(FILE *)0) {
         (void) rou_alert(0,"%s Unable to open 'count' qfile <%s> (error=<%s>)",
-                            OPEP,contact->cursesid,strerror(errno));
+                            OPEP,contact->session->sessid,strerror(errno));
         phase=999;
         }
       break;
     case 3      :       //inserting number of receipient
       if (fprintf(qfile,"%d\n",num)<1) {
         (void) rou_alert(0,"%s Unable to set 'count' in qfile <%s> (error=<%s>)",
-                            OPEP,contact->cursesid,strerror(errno));
+                            OPEP,contact->session->sessid,strerror(errno));
         (void) fclose(qfile);
         phase=999;      //trouble trouble
         }
@@ -404,7 +422,7 @@ while (proceed==true) {
     case 4      :       //closing count file
       if (fclose(qfile)!=0) {
         (void) rou_alert(0,"%s Unable to close qfile <%s> (error=<%s>)",
-                            OPEP,contact->cursesid,strerror(errno));
+                            OPEP,contact->session->sessid,strerror(errno));
         phase=999;      //trouble trouble
         }
       break;
@@ -449,7 +467,7 @@ while (proceed==true) {
   //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
   switch (phase) {
     case 0      :       //Creating the file
-      if ((trans=eml_createqfile(contact->cursesid,ext))==(FILE *)0) 
+      if ((trans=eml_createqfile(contact->session->sessid,ext))==(FILE *)0) 
         phase=999;      //trouble trouble
       break;
     case 1      :       //write data to trans file;
@@ -538,7 +556,7 @@ while (proceed==true) {
         }
       break;
     case 1      :       //opening the queue email
-      if ((queue=eml_createqfile(contact->cursesid,""))==(FILE *)0) 
+      if ((queue=eml_createqfile(contact->session->sessid,""))==(FILE *)0) 
         phase=999;      //trouble trouble
       break;
     case 2      :       //adding received stamp to file
@@ -582,7 +600,7 @@ while (proceed==true) {
         phase=999;      //Unable to create count file???
       break;
     case 7      :       //renameing directive
-      if (eml_renameqfile(contact->cursesid,EXTMP,EXTRANS)==false)
+      if (eml_renameqfile(contact->session->sessid,EXTMP,EXTRANS)==false)
         phase=999;              //Trouble trouble
       break;
     case 8      :       //everything fine
@@ -593,11 +611,11 @@ while (proceed==true) {
       total/=1024;    //KBytes
       delta=rou_getdifftime(&start);
       fmt="%d-3.5.3 Session ID=<%s>";
-      (void) transmit(contact,false,fmt,CMDOK,contact->cursesid);
+      (void) transmit(contact,false,fmt,CMDOK,contact->session->sessid);
       fmt="%d-3.5.3 data stream received: %d Kbytes within %d.%03d seconds)";
       (void) transmit(contact,false,fmt,CMDOK,total,delta/1000,delta%1000);
       fmt="%d 3.5.3 Message accepted for delivery";
-      (void) transmit(contact,true,fmt,CMDOK,contact->cursesid);
+      (void) transmit(contact,true,fmt,CMDOK,contact->session->sessid);
       done=true;
       proceed=false;    //task done
       break;
@@ -866,15 +884,14 @@ static _Bool doreset(CONTYP *contact,char *parameter)
 #define LOCSEQ  "2.1.0"
 
 (void) transmit(contact,true,"%d-%s flushed session %s",
-                              CMDOK,LOCSEQ,contact->cursesid);
+                              CMDOK,LOCSEQ,contact->session->sessid);
 contact->numreset++;
 contact->recipients=(RCPTYP **)rou_freelist((void **)(contact->recipients),
                                             (genfree_t)eml_freerecipient);
 contact->mailfrom=rou_freestr(contact->mailfrom);
-contact->cursesid=rou_freestr(contact->cursesid);
-contact->cursesid=eml_getcursesid(contact->mainsesid,contact->numreset);
+(void) getsessid(contact);
 (void) transmit(contact,true,"%d %s opening new session %s",
-                              CMDOK,LOCSEQ,contact->cursesid);
+                              CMDOK,LOCSEQ,contact->session->sessid);
 return true;
 
 #undef  LOCSEQ
@@ -1655,7 +1672,7 @@ while (proceed==true) {
       break;
     case 3      :       //Preparing contact
       contact->mainsesid=eml_getmainsesid();
-      contact->cursesid=eml_getcursesid(contact->mainsesid,contact->numreset);
+      (void) getsessid(contact);
       contact->locname=soc_getaddrinfo(contact->socptr,true,true);
       contact->locip=soc_getaddrinfo(contact->socptr,true,false);
       if (contact->locip!=(char *)0) {
@@ -1777,7 +1794,7 @@ if ((contact!=(CONTYP *)0)&&(contact->recipients!=(RCPTYP **)0)) {
     tra->code=(*ptr)->code;
     tra->date=isnow;
     tra->delay=0;
-    tra->sessid=strdup(contact->cursesid);
+    tra->sessid=strdup(contact->session->sessid);
     tra->mailfrom=strdup(contact->mailfrom);
     tra->rcptto=strdup(data);
     tralist=(TRATYP **)rou_addlist((void **)tralist,(void *)tra);
index 7a76eb3de737a040422841b67d9701ce4fe2acab..589f753309b14629004cdcab39b750f312908a97 100644 (file)
@@ -27,7 +27,7 @@ typedef struct  {
         char *peerip;           //socket remote peer IP
         int numreset;           //number of SMTP reset received
         char *mainsesid;        //session main ID
-        char *cursesid;         //current session ID
+        SESTYP *session;        //SMTP current session information
         char *mailfrom;         //current mail from originator
         RCPTYP **recipients;    //List of email recipient
         LOGPTR *logptr;         //reference to session log
index d4afd8f97d1e709489651f6f41991ee9db9a2658..90bd4159c826c9f5a974e77ee7441e01d12bcb71 100644 (file)
@@ -204,8 +204,7 @@ while (proceed==true) {
       break;
     case 3     :       //lets convert it
       afnnum->strnumip=afn_getstrip(afnnum);
-      //(void) printf("JMPDBG <%s> -> converted to <%s>\n",
-      //onecleanipstr,afnnum->strnumip);
+      //(void) printf("JMPDBG <%s> -> to <%s>\n", onecleanipstr,afnnum->strnumip);
       break;
     default    :       /*SAFE guard            */
       proceed=false;
@@ -403,9 +402,9 @@ while (proceed==true) {
           next++;
           } 
         if ((afnloc=getoneafn(ptr))!=(AFNTYP *)0) {
+          afnlist=(AFNTYP **)realloc(afnlist,(num+2)*sizeof(AFNTYP *));
           afnlist[num]=afnloc;
           num++;
-          afnlist=(AFNTYP **)realloc(afnlist,num*sizeof(AFNTYP *));
           afnlist[num]=(AFNTYP *)0;
           }
         ptr=next;
index 782f5e40f5a1717802bb6adcf195c6d6d4ea5864..bc5056d08a843832362b14fa4f5973cb6222b4c3 100644 (file)
@@ -25,7 +25,8 @@
 #define SSL_CIPHER_LIST "DEFAULT"
 
 static  _Bool modopen;    //module open/close status
-static  AFNTYP **afns;    //Binding information as AFN
+//Binding information as AFN
+static  AFNTYP **afns=(AFNTYP **)0;    
 /*
 ^L
 */
@@ -432,29 +433,29 @@ while (proceed==true) {
         char *newloc;
         char host[NI_MAXHOST];
 
-      if (ifa->ifa_addr==(struct sockaddr *)0)
-          continue;
-      family=ifa->ifa_addr->sa_family;
-      switch (family) {
-        case AF_INET  :
-          taille=sizeof(struct sockaddr_in);
-          break;
-        case AF_INET6 :
-          taille=sizeof(struct sockaddr_in6);
-          continue;   //No scanning for IPV6 Number (Jun 2025)
-          break;
-        default       :
+        if (ifa->ifa_addr==(struct sockaddr *)0)
+            continue;
+        family=ifa->ifa_addr->sa_family;
+        switch (family) {
+          case AF_INET  :
+            taille=sizeof(struct sockaddr_in);
+            break;
+          case AF_INET6 :
+            taille=sizeof(struct sockaddr_in6);
+            continue;   //No scanning for IPV6 Number (Jun 2025)
+            break;
+          default       :
+            continue;
+            break;
+          }
+        er=getnameinfo(ifa->ifa_addr,taille,host,NI_MAXHOST,NULL,0,NI_NUMERICHOST);
+        if (er!=0) {
+          (void) rou_alert(0,"%s etnameinfo() failed: (error=<%s> system?)",
+                             OPEP,strerror(errno));
           continue;
-          break;
-        }
-      er=getnameinfo(ifa->ifa_addr,taille,host,NI_MAXHOST,NULL,0,NI_NUMERICHOST);
-      if (er!=0) {
-        (void) rou_alert(0,"%s etnameinfo() failed: (error=<%s> system?)",
-                           OPEP,strerror(errno));
-        continue;
-        }
-      newloc=(char *)calloc(strlen(localip)+strlen(host)+3,sizeof(char));
-      if (strlen(localip)>0) {
+          }
+        newloc=(char *)calloc(strlen(localip)+strlen(host)+3,sizeof(char));
+        if (strlen(localip)>0) {
           (void) strcpy(newloc,localip);
           (void) strcat(newloc,",");
           }
@@ -465,6 +466,7 @@ while (proceed==true) {
       break;
     case 2      :       //converting interface IP list to AFNTYP list
       afns=afn_getipnum(localip);
+      (void) freeifaddrs(ifaddr);
       break;
     default     :       //SAFE Guard
       proceed=false;
@@ -1267,7 +1269,7 @@ return afns;
 int tls_modeunitls(_Bool mode)
 
 {
-#define OPEP    "unidoc.c:soc_modeunisoc"
+#define OPEP    "unitls.c:soc_modeunitls,"
 
 int status;