From 5b9203fb9a786f6d5c894b3c55e0e7349f9cd82b Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Sun, 15 Jun 2025 11:54:37 -0400 Subject: [PATCH] sending data in batch seems to be working (no memory leak) --- Makefile | 2 +- app/sender.c | 4 ++++ lib/geseml.c | 22 ++++++++++++++++++++++ lib/geseml.h | 5 ++++- lib/lvleml.c | 37 ++++++++++++++++++++++++------------- lib/unisig.c | 9 +++++---- lib/unitls.c | 7 +++++++ 7 files changed, 67 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index c0fb686..156a2b9 100644 --- a/Makefile +++ b/Makefile @@ -154,7 +154,7 @@ dbgsend : clean debug #-------------------------------------------------------------------- #testing feed -ONEFEED=feed01.tst +ONEFEED=feed03.tst FEEDPAR = \ $(TESTIP) \ diff --git a/app/sender.c b/app/sender.c index fcc457e..5891069 100644 --- a/app/sender.c +++ b/app/sender.c @@ -108,6 +108,8 @@ while (proceed==true) { break; case 3 : //dispatching email if (dispatcher(tra)==false) { //trouble backtracking file + (void) rou_alert(0,"%s JMPDBG <%s> dispatcher FALSE (Bug?)",OPEP,fname); + (void)eml_renameqfile(fname,EXDOING,EXTODO); phase=999; //No need to go further } @@ -121,6 +123,7 @@ while (proceed==true) { break; case 5 : //updating transfile (void) eml_dump_list_tra(qfile,tra); + tra=(TRATYP **)rou_freelist((void **)tra,(genfree_t)eml_freetra); break; case 6 : //closing file qfile=eml_closeqfile(qfile); @@ -135,6 +138,7 @@ while (proceed==true) { status=true; break; default : //SAFE Guard + //tra=(TRATYP **)rou_freelist((void **)tra,(genfree_t)eml_freetra); qfile=eml_closeqfile(qfile); proceed=false; break; diff --git a/lib/geseml.c b/lib/geseml.c index 0a72ace..ddce478 100644 --- a/lib/geseml.c +++ b/lib/geseml.c @@ -277,6 +277,28 @@ return tra; */ /********************************************************/ /* */ +/* Procedure to duplcate an resp list within a tra */ +/* record. */ +/* */ +/********************************************************/ +PUBLIC void eml_duptra_resp(TRATYP *tra,char **resp) + +{ +if (tra!=(TRATYP *)0) { + (void) eml_freetra_resp(tra); + if (resp!=(char **)0) { + while (*resp!=(char *)0) { + tra->resp=(char **)rou_addlist((void **)tra->resp,strdup(*resp)); + resp++; + } + } + } +} +/* + +*/ +/********************************************************/ +/* */ /* Procedure to duplicate TRATYP structure */ /* */ /********************************************************/ diff --git a/lib/geseml.h b/lib/geseml.h index 31d1be4..df3206e 100644 --- a/lib/geseml.h +++ b/lib/geseml.h @@ -30,9 +30,12 @@ extern _Bool eml_dump_one_tra(FILE *out,TRATYP *tra); //procedure to dump a list of transfert record extern _Bool eml_dump_list_tra(FILE *out,TRATYP **tra); -//procedure to fee memory used by the resp rercord within TRATYP structure +//procedure to fee memory used by the resp record within TRATYP structure extern void eml_freetra_resp(TRATYP *tra); +//procedure to fee memory used to duplicate a resp list to tra resp +extern void eml_duptra_resp(TRATYP *tra,char **resp); + //procedure to fee memory used by a TRATYP structure extern TRATYP *eml_freetra(TRATYP *tra); diff --git a/lib/lvleml.c b/lib/lvleml.c index d09bd7f..63ff4fc 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -1059,23 +1059,29 @@ return rmt; static _Bool reset_mx(RMTTYP *rmt) { +#define OPEP "lvleml.c:reset_mx," + _Bool ok; -int phase; -_Bool proceed; +int rspcode; +char **resp; ok=false; -phase=0; -proceed=true; -while (proceed==true) { - switch (phase) { - break; - default : //SAFE Guard - proceed=false; - break; - } - phase++; +resp=(char **)0; +rspcode=tcp_smtp_command(rmt,&resp,"RSET"); +switch (rspcode) { + case CMDOK : //Everythin fine + ok=true; + break; + default : + (void) rou_alert(0,"%s Unexpected code='%d' (Code?)",OPEP,rspcode); + for (int i=0;resp[i]!=(char *)0;i++) + (void) rou_alert(0,"%s resp[%d]=<%s>",OPEP,i,resp[i]); + break; } +resp=(char **)rou_freelist((void **)resp,(genfree_t)rou_freestr); return ok; + +#undef OPEP } /* ^L @@ -1094,12 +1100,14 @@ int rspcode; int sent; TIMESPEC start; char *sessid; +char **resp; int phase; _Bool proceed; rspcode=0; sent=0; sessid=(*tosend)->sessid; +resp=(char **)0; phase=0; proceed=true; (void) clock_gettime(CLOCK_REALTIME,&start); @@ -1122,7 +1130,7 @@ while (proceed==true) { break; case 2 : //send the text termination (void) tcp_write(rmt->socptr,"."); - rspcode= tcp_get_smtp_reply(rmt,WAITRMT,(char ***)0); + rspcode= tcp_get_smtp_reply(rmt,WAITRMT,&resp); break; case 3 : //sending session data const char *fmt; @@ -1151,6 +1159,7 @@ while (proceed==true) { dest=tosend; while (*dest!=(TRATYP *)0) { + (void) eml_duptra_resp(*dest,resp); switch ((*dest)->sendcode) { case CMDOK : if (rspcode==CMDOK) { @@ -1174,6 +1183,7 @@ while (proceed==true) { } phase++; } +resp=(char **)rou_freelist((void **)resp,(genfree_t)rou_freestr); #undef OPEP } /* @@ -1763,6 +1773,7 @@ while (proceed==true) { *ptr='\000'; (void) snprintf(cmt,sizeof(cmt),"main-session-id=%s",mainsesid); logptr=log_openlog(mainsesid,false,cmt); + mainsesid=rou_freestr(mainsesid); break; case 3 : //sending all email within transaction (void) sending_email(logptr,tra); diff --git a/lib/unisig.c b/lib/unisig.c index 79bb4ab..3a90915 100644 --- a/lib/unisig.c +++ b/lib/unisig.c @@ -123,6 +123,7 @@ switch (sig) APPNAME,debug); break; case SIGPIPE : + (void) rou_alert(0,"%s JMPDBG got SIGPIPE",APPNAME); break; default : (void) rou_alert(0,"Unexpected Signal [%d]/<%s> received", @@ -185,8 +186,8 @@ if (onoff==true) { (void) sigaction(SIGQUIT,newsa,olds[4]); (void) sigaction(SIGHUP,newsa,olds[5]); (void) sigaction(SIGALRM,newsa,olds[6]); - (void) sigaction(SIGPIPE,newsa,olds[7]); - (void) sigaction(SIGCHLD,newsa,olds[8]); + (void) sigaction(SIGCHLD,newsa,olds[7]); + (void) sigaction(SIGPIPE,newsa,olds[8]); (void) free(newsa); if ((sfd=signalfd(-1, &mask, 0))<0) { (void) rou_alert(0,"%s Unable to set signalfd (error=<%s>)", @@ -196,8 +197,8 @@ if (onoff==true) { else { int i; - (void) sigaction(SIGCHLD,olds[8],(struct sigaction *)0); - (void) sigaction(SIGPIPE,olds[7],(struct sigaction *)0); + (void) sigaction(SIGPIPE,olds[8],(struct sigaction *)0); + (void) sigaction(SIGCHLD,olds[7],(struct sigaction *)0); (void) sigaction(SIGALRM,olds[6],(struct sigaction *)0); (void) sigaction(SIGHUP,olds[5],(struct sigaction *)0); (void) sigaction(SIGQUIT,olds[4],(struct sigaction *)0); diff --git a/lib/unitls.c b/lib/unitls.c index 5ed6349..c2cd20d 100644 --- a/lib/unitls.c +++ b/lib/unitls.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -784,10 +785,16 @@ while (proceed==true) { } break; case 1 : //set certificate + //valgrind is trapping SIGPIPE and stop + struct sigaction oldsa; + + (void) sigaction(SIGPIPE,(struct sigaction *)0,&oldsa); + (void) signal(SIGPIPE, SIG_IGN); status=SSL_shutdown(tls->ssl); if (status<0) (void) rou_alert(0,"%s, Link with [%s], ssl_shutdown status='%d'", OPEP,tls->peerip,status); + (void) sigaction(SIGPIPE,&oldsa,(struct sigaction *)0); break; default : //SAFE guard tls=freetls(tls); -- 2.47.3