From: Jean-Marc Pigeon (Delson) Date: Sun, 11 Aug 2024 15:03:46 +0000 (-0400) Subject: Tools to check about memory leak seems to be working X-Git-Tag: tag-0.4.1~1 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=3fd45cca4bbfca6543825cb43a94b0bac42a4871;p=jmp%2Fmailleur Tools to check about memory leak seems to be working --- diff --git a/lib/devsoc.c b/lib/devsoc.c index 573eff5..7d895d2 100644 --- a/lib/devsoc.c +++ b/lib/devsoc.c @@ -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); diff --git a/lib/modrec.c b/lib/modrec.c index 7c94a63..82efff1 100644 --- a/lib/modrec.c +++ b/lib/modrec.c @@ -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; diff --git a/lib/subrou.c b/lib/subrou.c index 67ce4d4..2299b97 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -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 +} +/* + +*/ +/********************************************************/ +/* */ /* 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) { diff --git a/lib/subrou.h b/lib/subrou.h index 68a94a8..438fe57 100644 --- a/lib/subrou.h +++ b/lib/subrou.h @@ -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); diff --git a/lib/unitls.c b/lib/unitls.c index e1742fd..f8efe35 100644 --- a/lib/unitls.c +++ b/lib/unitls.c @@ -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); diff --git a/lib/unitls.h b/lib/unitls.h index 354d940..e1de541 100644 --- a/lib/unitls.h +++ b/lib/unitls.h @@ -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