Browse Source

Resolves: bug 458677
Bug Description: Memory leaks in index code doing indexed & range & matching rule searches
Reviewed by: nkinder (Thanks!)
Branch: HEAD
Fix Description: This leak occurs when doing ranged, indexed searches. The code calls
index2prefix to get the index prefix. In the case of a matching rule search,
this prefix is allocated. The function free_prefix was not being called in all
cases.
Platforms tested: RHEL5, Fedora 8
Flag Day: no
Doc impact: no
QA impact: should be covered by regular nightly and manual testing
New Tests integrated into TET: none

Rich Megginson 17 years ago
parent
commit
b621e8594f
1 changed files with 10 additions and 2 deletions
  1. 10 2
      ldap/servers/slapd/back-ldbm/index.c

+ 10 - 2
ldap/servers/slapd/back-ldbm/index.c

@@ -1047,7 +1047,7 @@ index_range_read(
     DBT    cur_key = {0};
     DBT    data = {0} ;
     IDList *idl= NULL;
-    char   *prefix;
+    char   *prefix = NULL;
     char   *realbuf, *nextrealbuf;
     size_t reallen, nextreallen;
     size_t plen;
@@ -1100,10 +1100,14 @@ index_range_read(
         LDAPDebug( LDAP_DEBUG_ANY,
               "<= index_range_read(%s,%s) NULL (operator %i)\n",
               type, prefix, operator );
+        free_prefix(prefix);
         return( NULL );
     }
     ainfo_get( be, type, &ai );
-    if (ai == NULL) return NULL;
+    if (ai == NULL) {
+        free_prefix(prefix);
+        return NULL;
+    }
     LDAPDebug( LDAP_DEBUG_ARGS, "   indextype: \"%s\" indexmask: 0x%x\n",
         indextype, ai->ai_indexmask, 0 );
     if ( !is_indexed( indextype, ai->ai_indexmask, ai->ai_index_rules )) {
@@ -1111,12 +1115,14 @@ index_range_read(
         LDAPDebug( LDAP_DEBUG_TRACE,
             "<= index_range_read(%s,%s) %lu candidates (allids)\n",
             type, prefix, (u_long)IDL_NIDS(idl) );
+        free_prefix(prefix);
         return( idl );
     }
     if ( (*err = dblayer_get_index_file( be, ai, &db, DBOPEN_CREATE )) != 0 ) {
         LDAPDebug( LDAP_DEBUG_ANY,
             "<= index_range_read(%s,%s) NULL (could not open index file)\n",
             type, prefix, 0 );
+        free_prefix(prefix);
         return( NULL ); /* why not allids? */
     }
     if (NULL != txn) {
@@ -1130,6 +1136,7 @@ index_range_read(
             "<= index_range_read(%s,%s) NULL: db->cursor() == %i\n",
             type, prefix, *err );
         dblayer_release_index_file( be, ai, db );
+        free_prefix(prefix);
         return( NULL ); /* why not allids? */
     }
 
@@ -1377,6 +1384,7 @@ index_range_read(
         }
 #endif
 error:
+    free_prefix(prefix);
     DBT_FREE_PAYLOAD(cur_key);
     DBT_FREE_PAYLOAD(upperkey);