[Fedora-directory-commits] ldapserver/ldap/servers/slapd util.c, 1.14, 1.15 sasl_io.c, 1.11, 1.12

Noriko Hosoi (nhosoi) fedora-directory-commits at redhat.com
Wed Oct 3 00:55:37 UTC 2007


Author: nhosoi

Update of /cvs/dirsec/ldapserver/ldap/servers/slapd
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv32219/slapd

Modified Files:
	util.c sasl_io.c 
Log Message:
Resolves: #196523
Summary: miscellaneous memory leaks
Description: 1) fixed memory leaks
2) cleaned up normalize_path code with fixing memory leaks



Index: util.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/util.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- util.c	4 Dec 2006 18:36:56 -0000	1.14
+++ util.c	3 Oct 2007 00:55:35 -0000	1.15
@@ -402,61 +402,63 @@
 static void
 clean_path(char **norm_path)
 {
-	char **np;
+    char **np;
 
-	for (np = norm_path; np && *np; np++)
-		slapi_ch_free((void **)np);
-	slapi_ch_free((void  **)&norm_path);
+    for (np = norm_path; np && *np; np++)
+        slapi_ch_free_string(np);
+    slapi_ch_free((void  **)&norm_path);
 }
 
 static char **
 normalize_path(char *path)
 {
-    char *dname = slapi_ch_strdup(path);
-    char *dnamep = dname;
-    char *bnamep = NULL;
+    char *dname = NULL;
+    char *dnamep = NULL;
     char **dirs = (char **)slapi_ch_calloc(strlen(path), sizeof(char *));
     char **rdirs = (char **)slapi_ch_calloc(strlen(path), sizeof(char *));
     char **dp = dirs;
     char **rdp;
+    int elimdots = 0;
+
+    if (NULL == path || '\0' == *path) {
+        return NULL;
+    }
+
+    dname = slapi_ch_strdup(path);
     do {
-        bnamep = strrchr(dnamep, _CSEP);
-        if (NULL == bnamep) {
-            bnamep = dnamep;
+        dnamep = strrchr(dname, _CSEP);
+        if (NULL == dnamep) {
+            dnamep = dname;
         } else {
-            *bnamep = '\0';
-            bnamep++;
+            *dnamep = '\0';
+            dnamep++;
         }
-        if (0 != strcmp(bnamep, ".")) {
-            *dp++ = slapi_ch_strdup(bnamep);    /* remove "/./" in the path */
+        if (0 != strcmp(dnamep, ".") && strlen(dnamep) > 0) {
+            *dp++ = slapi_ch_strdup(dnamep); /* rm "/./" and "//" in the path */
         }
-    } while (NULL != dnamep && '\0' != *dnamep && /* done or relative path */
-             !(0 == strcmp(dnamep, ".") && 0 == strcmp(bnamep, ".")));
+    } while ( dnamep > dname /* == -> no more _CSEP */ );
+    slapi_ch_free_string(&dname);
 
     /* remove "xxx/.." in the path */
     for (dp = dirs, rdp = rdirs; dp && *dp; dp++) {
         while (*dp && 0 == strcmp(*dp, "..")) {
             dp++; 
-            if (rdp > rdirs)
-                rdp--;
+            elimdots++;
         }
-        if (*dp)
+        if (elimdots > 0) {
+            elimdots--;
+        } else if (*dp) {
             *rdp++ = slapi_ch_strdup(*dp);
-    }
-    for (--dp, rdp = rdirs; dp >= dirs; dp--) {
-        while (*dp && 0 == strcmp(*dp, "..")) {
-            dp--; 
-            if (rdp > rdirs)
-                rdp--;
         }
-        if (*dp && strlen(*dp) > 0)
-            *rdp++ = slapi_ch_strdup(*dp);
     }
-    *rdp = NULL;
+    /* reverse */
+    for (--rdp, dp = rdirs; rdp >= dp && rdp >= rdirs; --rdp, dp++) {
+        char *tmpp = *dp;
+        *dp = *rdp;
+        *rdp = tmpp;
+    }
 
     clean_path(dirs);
-    slapi_ch_free_string(&dname);
-
     return rdirs;
 }
 


Index: sasl_io.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/sasl_io.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- sasl_io.c	25 Apr 2007 20:24:31 -0000	1.11
+++ sasl_io.c	3 Oct 2007 00:55:35 -0000	1.12
@@ -139,6 +139,7 @@
 sasl_io_cleanup(Connection *c)
 {
     int ret = 0;
+    struct lber_x_ext_io_fns *func_pointers = NULL;
     sasl_io_private *sp = c->c_sasl_io_private;
     if (sp) {
         LDAPDebug( LDAP_DEBUG_CONNS,
@@ -147,6 +148,8 @@
         slapi_ch_free((void**)&(sp->encrypted_buffer));
         slapi_ch_free((void**)&(sp->decrypted_buffer));
         /* Put the I/O functions back how they were */
+        ber_sockbuf_get_option( c->c_sb, LBER_SOCKBUF_OPT_EXT_IO_FNS, &func_pointers);
+        slapi_ch_free((void**)&func_pointers);
         ber_sockbuf_set_option( c->c_sb, LBER_SOCKBUF_OPT_EXT_IO_FNS, sp->real_iofns);
         slapi_ch_free((void**)&sp);
         c->c_sasl_io_private = NULL;




More information about the Fedora-directory-commits mailing list