فهرست منبع

Bug 663597 - Memory leaks in normalization code

The DN normalization code uses a Slapi_Attr on the stack to avoid
allocation of the struct.  The contents of the Slapi_Attr are
never freed.  This patch ensure that the struct is cleared out
properly.

There was also a leak in the syntax normalization code where a
pointer to recently allocated string could get overwritten without
freeing the string first.  This patch frees the string first.
Nathan Kinder 15 سال پیش
والد
کامیت
4da627a74d
2فایلهای تغییر یافته به همراه6 افزوده شده و 3 حذف شده
  1. 3 3
      ldap/servers/slapd/attrsyntax.c
  2. 3 0
      ldap/servers/slapd/dn.c

+ 3 - 3
ldap/servers/slapd/attrsyntax.c

@@ -469,14 +469,14 @@ char *
 slapi_attr_syntax_normalize( const char *s )
 {
 	struct asyntaxinfo *asi = NULL;
-	char *r;
-	
+	char *r = NULL;
 
-    if((asi=attr_syntax_get_by_name(s)) != NULL ) {
+	if((asi=attr_syntax_get_by_name(s)) != NULL ) {
 		r = slapi_ch_strdup(asi->asi_name);
 		attr_syntax_return( asi );
 	}
 	if ( NULL == asi ) {
+		slapi_ch_free_string( &r );
 		r = attr_syntax_normalize_no_lookup( s );
 	}
 	return r;

+ 3 - 0
ldap/servers/slapd/dn.c

@@ -576,6 +576,7 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len)
 
                 slapi_attr_init(&test_attr, typestart);
                 is_dn_syntax = slapi_attr_is_dn_syntax_attr(&test_attr);
+                attr_done(&test_attr);
 
                 /* Reset the character we modified. */
                 *d = savechar;
@@ -596,6 +597,7 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len)
 
                 slapi_attr_init(&test_attr, typestart);
                 is_dn_syntax = slapi_attr_is_dn_syntax_attr(&test_attr);
+                attr_done(&test_attr);
 
                 /* Reset the character we modified. */
                 *d = savechar;
@@ -616,6 +618,7 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len)
 
                 slapi_attr_init(&test_attr, typestart);
                 is_dn_syntax = slapi_attr_is_dn_syntax_attr(&test_attr);
+                attr_done(&test_attr);
 
                 /* Reset the character we modified. */
                 *d = savechar;