]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Tools to check about memory leak seems to be working
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 11 Aug 2024 15:03:46 +0000 (11:03 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 11 Aug 2024 15:03:46 +0000 (11:03 -0400)
lib/devsoc.c
lib/modrec.c
lib/subrou.c
lib/subrou.h
lib/unitls.c
lib/unitls.h

index 573eff57f9afac10bbe4430044b0fc70e42be9a7..7d895d20644a3b7ed66443fa677406a47dbb2886 100644 (file)
@@ -991,8 +991,12 @@ while (proceed==true) {
     case 1      :       //shutting down the TCP link
       switch (soc->proto) {
         case pro_smtp           :       //plain socket
+          break;
         case pro_starttls       :       //plain socket + STARTTLS
-                                        //nothing to do
+          if (soc->modtls==true) {
+            soc->tls=tls_closetls(soc->tls);
+            soc->modtls=false;
+            }
           break;
         case pro_smtps          :       //set secure socket
           soc->tls=tls_closetls(soc->tls);
index 7c94a63d17b18014d82c7e48aa25ac3048001509..82efff12a1566defa0aeef133f770efc48e6ef1d 100644 (file)
@@ -52,7 +52,10 @@ while (proceed==true) {
         phase=999;      //No contact!
       break;
     case 1      :       //within forked process
-      printf("New client [%s] connected\n",contact->peerip);
+      (void) prc_settitle("Processing incoming contact from [%s] on [%s:%s]",
+                            contact->peerip,contact->locname,contact->locserv);
+      (void) rou_checkleak(true);
+      printf("New client [%s] connected pid='%05d'\n",contact->peerip,getpid());
       break;
     case 2      :       //do contact
       switch (eml_docontact(contact)) {
@@ -68,6 +71,7 @@ while (proceed==true) {
       break;
     case 3      :       //connection terminated
       contact=tcp_dropcontact(contact);
+      (void) rou_checkleak(false);
       break;
     default     :       //SAFE guard
       proceed=false;
index 67ce4d462628179c5495e5fc4b377f999bbed54e..2299b979ce1fe49257a1f84d89dcdeb1364fbddd 100644 (file)
@@ -19,8 +19,8 @@
 
 
 //version definition 
-#define VERSION "0.3"
-#define RELEASE "42"
+#define VERSION "0.4"
+#define RELEASE "1"
 
 //Public variables
 PUBLIC  int debug=0;            //debug level
@@ -63,12 +63,54 @@ return dropzone;
 */
 /********************************************************/
 /*                                                      */
+/*     This procedure is working tandem with libleak   */
+/*      to detect memory leak within specfic part of    */
+/*      code.                                           */
+/*     Tools as valgrind can not be used as most of    */
+/*      the application is forked in daemon state.      */
+/*      memory leak must be detected on a "long" run    */
+/*      forgetting about parent process apparent leak.  */
+/*      (forked process are created with parent memory  */
+/*      copy)                                           */
+/*                                                      */
+/********************************************************/
+PUBLIC void rou_checkleak(_Bool onoff)
+
+{
+#define ENABLE  "/tmp/libleak.enabled"
+
+static  _Bool current=false;
+
+if (current!=onoff) {
+  int status;
+  char cmd[200];
+
+  switch (onoff) {
+    case true   :
+      (void) snprintf(cmd,sizeof(cmd),"echo %d >> %s",getpid(),ENABLE);
+      break;
+    case false  :
+      (void) snprintf(cmd,sizeof(cmd),"sed -i '/%d/d' %s",getpid(),ENABLE);
+      break;
+    }
+  if ((status=system(cmd))!=0) {
+    (void) rou_alert(0,"status '%d' to memleak command <%s> (bug?)",status,cmd);
+    }
+  current=onoff;
+ }
+#undef  ENABLE
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
 /*     Procedure to transform the local system time in */
 /*     ASCII time stamp.                               */
 /*     Stored in STATIC memory area.                   */
 /*                                                      */
 /********************************************************/
-char *rou_ascsysstamp(time_t curtime)
+PUBLIC char *rou_ascsysstamp(time_t curtime)
 
 {
 #define TSTAMP "%a, %d %b %Y %T %z"
@@ -101,7 +143,7 @@ return VERSION"."RELEASE;
 /*     string, do not proceed if pointer is NULL.       */
 /*                                                      */
 /********************************************************/
-char *rou_freestr(register char *str)
+PUBLIC char *rou_freestr(register char *str)
 
 {
 if (str!=(char *)0) {
index 68a94a8009e19dec8e3ca0435811bca67ab530cd..438fe57349e2a0116c9dfe3aa9859903d6ba71d5 100644 (file)
@@ -28,6 +28,9 @@ extern char          *appname;  //application "official" name
 
 //---   Routines implemented within subrou.c    ---------
 
+//open/close memory leak detector.
+extern void rou_checkleak(_Bool onoff);
+
 //transform local system time in ASCII stamp.
 extern char *rou_ascsysstamp(time_t curtime);
 
index e1742fd046f0959c44e04a3ed401efcf03a1cfc5..f8efe358a9ba8be5bd9bf0318466edab5b7459bb 100644 (file)
@@ -196,8 +196,10 @@ if (tls!=(TLSTYP *)0) {
   tls->peerip=rou_freestr(tls->peerip);
   tls->locip=rou_freestr(tls->locip);
   tls->locport=rou_freestr(tls->locport);
-  if (tls->ssl!=(SSL *)0)
-    (void) free(tls->ssl);
+  if (tls->ssl!=(SSL *)0) {
+    (void) SSL_clear(tls->ssl);
+    (void) SSL_free(tls->ssl);
+    }
   if (tls->ctx!=(SSL_CTX *)0)
     (void) SSL_CTX_free(tls->ctx);
   (void) free(tls);
index 354d94035ced4b923efd0fa82ba4ce8245fc3dce..e1de541db9b766abae32268f4939dba4c21e2067 100644 (file)
@@ -20,7 +20,7 @@ typedef struct  {
         char *locport;  //local Port number
         SSL_CTX *ctx;   //SSL context
         SSL *ssl;       //SSL link
-        BIO *bio;       //SSL Basic input output
+        //BIO *bio;       //SSL Basic input output
         }TLSTYP;
 
 //procedure to open an tls channel