]> SAFE projects GIT repository - jmp/mailleur/commitdiff
tools about memory leak
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sat, 3 Aug 2024 23:55:00 +0000 (19:55 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sat, 3 Aug 2024 23:55:00 +0000 (19:55 -0400)
kleenex/Makefile
kleenex/memleak.c [new file with mode: 0644]
lib/devsoc.c
lib/gestcp.c
lib/modrec.c
lib/subrou.c

index 45682856145b54a414e26dc6d44d955bc430f63b..82dc6b172b098a2d255ec6c50f8303e1c3ac811e 100644 (file)
@@ -2,7 +2,11 @@ debug  : server
 
 server :  server.c
 
+memleak        :  memleak.c
+
 clean  :  
-          @ rm -f server server.o
+          @ rm -f server memleak
+          @ rm -f *.o
 
 CFLAGS = -Wall -D_GNU_SOURCE -g
+LDFLAGS        = -g
diff --git a/kleenex/memleak.c b/kleenex/memleak.c
new file mode 100644 (file)
index 0000000..1ec908f
--- /dev/null
@@ -0,0 +1,16 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <mcheck.h>
+
+int main() {
+
+    for (int i = 0; i < 10; i++) {
+
+        int *leak = (int *) malloc(sizeof(int) * 10);
+        printf("Memory allocated at iteration %d ptr=%p\n",i,leak);
+       (void) sleep(2);
+    }
+
+    return 0;
+}
index 0113200bfbdd922047d0c68037a9f345aa5b5ae0..9869696beb4b7c9dad70065712e60c4829ae3497 100644 (file)
@@ -30,6 +30,7 @@ typedef struct  {
         PROTYP proto;   //Connexion protocol type
         char *ip;       //Binding IP    //IPV4 or IPV6
         char *port;     //Binding Port
+        char *hostname; //binding hostname
         time_t lasttry; //successful binding last time
         int iteration;  //number of soc slot used on the IP
         int handle;     //connexion handle
@@ -53,8 +54,9 @@ if (socptr!=(SOCPTR *)0) {
   register SOCTYP *soc;
 
   soc=(SOCTYP *)socptr;
-  soc->port=rou_freestr(soc->port);
+  soc->hostname=rou_freestr(soc->hostname);
   soc->ip=rou_freestr(soc->ip);
+  soc->port=rou_freestr(soc->port);
   (void) free(soc);
   socptr=(SOCPTR *)0; 
   }
index 59e62035fc93b1222027adcb370f17a19d8a72b8..7df10ced585b76c4f818663a9c97dbd9216e022b 100644 (file)
@@ -92,14 +92,10 @@ if (contact!=(CONTYP *)0) {
                             OPEP,strerror(errno));
       }
     }
-  if (contact->carpile!=(char *)0)
-    (void) free(contact->carpile);
-  if (contact->EOL!=(char *)0)
-    (void) free(contact->EOL);
-  if (contact->peerip!=(char *)0)
-    (void) free(contact->peerip);
-  if (contact->locname!=(char *)0)
-    (void) free(contact->locname);
+  contact->carpile=rou_freestr(contact->carpile);
+  contact->EOL=rou_freestr(contact->EOL);
+  contact->peerip=rou_freestr(contact->peerip);
+  contact->locname=rou_freestr(contact->locname);
   (void) free(contact);
   contact=(CONTYP *)0;
   }
@@ -201,7 +197,7 @@ while (proceed==true) {
         phase=999;      //No End Of Line yet
       break;
     case 2      :       //duplicating carpile
-      *lineptr=calloc(tact->carin,sizeof(char));
+      *lineptr=calloc(tact->carin+1,sizeof(char));
       *eol='\000';
       (void) strcpy(*lineptr,tact->carpile);
       (void) strcat(*lineptr,tact->EOL);
@@ -371,6 +367,9 @@ while (proceed==true) {
 
         char signon[100];
 
+        (void) prc_settitle("Contact from peer '%s' started at %s",
+                             contact->peerip, 
+                             rou_ascsysstamp(time((time_t *)0)));
         (void) snprintf(signon,sizeof(signon),FMT,
                                       SIGNON,contact->locname,
                                       appname,rou_getversion(),
index 162c0888a445d9c322a5f992b43b71adbf8581d8..e85115662ff1c3b838f46ba429d600072c290733 100644 (file)
@@ -5,6 +5,7 @@
 /*                                                     */
 /********************************************************/
 #include        <errno.h>
+#include        <mcheck.h>
 #include        <stdio.h>
 #include        <stdlib.h>
 #include        <string.h>
@@ -58,8 +59,9 @@ while (proceed==true) {
         TIMESPEC attend;
         char *line;
         int got;
+        _Bool quit;
 
-        attend.tv_sec=20;
+        attend.tv_sec=60;
         attend.tv_nsec=0;
         (void) printf("attend %d seconds\n",(int)attend.tv_sec);
         got=tcp_getline(contact,&attend,&line);
@@ -68,12 +70,13 @@ while (proceed==true) {
           break;        //remote disconnect
           }
         (void) printf("Read '%d' char =<%s>\n",got,line);
-        if (strcasecmp(line,"QUIT"CRLF)==0) {
+        quit=(strcasecmp(line,"QUIT"CRLF)==0);
+        (void) tcp_write(contact,line,strlen(line));
+        (void) free(line);
+        if (quit==true) {
           (void) printf("remote quit\n");
           break;        //remote disconnect
           }
-        (void) tcp_write(contact,line,strlen(line));
-        (void) free(line);
         }
       break;
     case 3      :       //connection terminated
index ceb27515aae002d5c7690de71d530797512ccd58..32532c19eb653ed9068f8853ce4d4468a2cb527b 100644 (file)
@@ -20,7 +20,7 @@
 
 //version definition 
 #define VERSION "0.3"
-#define RELEASE "18"
+#define RELEASE "19"
 
 //Public variables
 PUBLIC  int debug=0;            //debug level