]> code.citadel.org Git - citadel.git/commitdiff
* Working on cleaning up code. There were LOTS of missing free() calls.
authorBrian <brian@uncensored.citadel.org>
Tue, 12 Jun 2001 11:47:44 +0000 (11:47 +0000)
committerBrian <brian@uncensored.citadel.org>
Tue, 12 Jun 2001 11:47:44 +0000 (11:47 +0000)
Boy, was I lazy...  :)

  This library is MUCH more stable than it was at 0.59-RELEASE checkpoint,
  but it still has a few leaky issues.  I'm still working on fixing it.

libCxClient/src/libtransport.c
libCxClient/src/testlib.c
libCxClient/src/users.c

index d763eee7e885aff47736773580256ce1a5fe3e56..b8d06a6c8976a97e00987de449134c508603c533 100644 (file)
@@ -105,7 +105,7 @@ CXHNDL              ret = 0;
 
        DPF((DFA, "Creating new CXTBL handle."));
 
-       ret = (CXHNDL) malloc( sizeof(CXTBLENT) );
+       ret = (CXHNDL) CxMalloc( sizeof(CXTBLENT) );
        if(ret<=0) return(NULL);
 
        /**
@@ -175,10 +175,12 @@ char              *tmp;
        DPF((DFA,"Copying host"));
        if(host && *host) {
                if(strlen(host) >= 254) {
-                       tmp = strdup(host);
+                       tmp = (char *)CxMalloc( 255 );
+                       strcpy( tmp, host );
                        tmp[254] = 0;
                        strcpy(n->host, tmp);
-                       free(tmp);
+                       CxFree(tmp);
+
                } else {
                        strcpy(n->host, host);
                }
@@ -187,10 +189,11 @@ char              *tmp;
        DPF((DFA,"Copying user"));
        if(user && *user) {
                if(strlen(user) >= 64) {
-                       tmp = strdup(user);
+                       tmp = (char *)CxMalloc( 65 );
+                       strcpy( tmp, user );
                        tmp[64] = 0;
                        strcpy(n->user, tmp);
-                       free(tmp);
+                       CxFree(tmp);
                } else {
                        strcpy(n->user, user);
                }
@@ -199,10 +202,11 @@ char              *tmp;
        DPF((DFA,"Copying pass"));
        if(pass && *pass) {
                if(strlen(pass) >= 64) {
-                       tmp = strdup(pass);
+                       tmp = (char *)CxMalloc( 65 );
+                       strcpy( tmp, pass );
                        tmp[64] = 0;
                        strcpy(n->pass, tmp);
-                       free(tmp);
+                       CxFree(tmp);
                } else {
                        strcpy(n->pass, pass);
                }
@@ -260,7 +264,7 @@ CXHNDL              p;
                 ** This was the only entry in the CxTbl.
                 **/
                if( !p->_next && !p->_prev ) {
-                       free(p);
+                       CxFree(p);
                        g_CxTbl = NULL;
 
                /**
@@ -272,7 +276,7 @@ CXHNDL              p;
 
                        if( g_CxTbl == p ) g_CxTbl = p->_next;
 
-                       free( p );
+                       CxFree(p);
                }
        }
        DPF((DFA,"g_CxTbl @0x%08x", g_CxTbl));
@@ -331,15 +335,23 @@ CXHNDL            e;
 
 /**
  ** CxClGetUser(): Set the username for a specific connection handle.
+ ** [*] FREE the results of this operation!!
  **/
 char           *CxClGetUser( int id ) {
 CXHNDL         e;
+char           *ret;
 
        e = _CxTbEntry( g_CxTbl, id );
        if(!e) return(NULL);
 
-       if(e->user) return(strdup(e->user));
-       else return(NULL);
+       if(e->user[0]) {
+               ret = (char *)CxMalloc( strlen( e->user ) + 1 );
+               strcpy( ret, e->user );
+               return( ret );
+
+       } else {
+               return(NULL);
+       }
 }
 
 /**
@@ -362,12 +374,19 @@ CXHNDL            e;
  **/
 char           *CxClGetPass( int id ) {
 CXHNDL         e;
+char           *ret;
 
        e = _CxTbEntry( g_CxTbl, id );
        if(!e) return(NULL);
 
-       if(e->user) return(strdup(e->pass));
-       else return(NULL);
+       if(e->pass) {
+               ret = (char *)CxMalloc( strlen(e->pass) +1 );
+               strcpy(ret, e->pass);
+               return(ret);
+
+       } else {
+               return(NULL);
+       }
 }
 
 /**
index d3316fc0b4c7866bff4bc3ae3ea56f95475d3574..65ec078d7c12d219bb55a771399bc6ec0bbbd861 100644 (file)
@@ -71,6 +71,7 @@ int           hndl;
                }
 
                CxClCbShutdown();
+               CxClDelete( hndl );
 
        } else {
                printf("Unable to connect to '%s'!\n", argv[1]);
index c14f087bd3e9b76a26f351f6a633e04bbc55ae09..e62e8b6991cf6e505bd848e517ce4cd22f660bd7 100644 (file)
@@ -149,15 +149,17 @@ int               rc;
                        sprintf(xmit,"PASS %s",passwd);
                } else {
                        tmp = CxClGetPass( id );
-                       if(!tmp) tmp = strdup("");
-
-                       xmit = (char *)CxMalloc(strlen(tmp)+6);
-                       sprintf(xmit,"PASS %s",tmp);
+                       if(tmp) {
+                               xmit = (char *)CxMalloc(strlen(tmp)+6);
+                               sprintf(xmit,"PASS %s",tmp);
+                       } else {
+                               xmit = (char *)CxMalloc(6);
+                               sprintf(xmit, "PASS ");
+                       }
                }
                CxClSend(id, xmit);
                CxFree(xmit);
-
-               if(tmp) free(tmp);
+               if(tmp) CxFree(tmp);
 
                DPF((DFA,"Validating password"));
                rc = CxClRecv(id, buf);