]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/attr.c
Plug mutex/rwlock leaks (destroy them)
[openldap] / servers / slapd / attr.c
index 8204fa7be860406b9f16cc9505a7dff3506b9eb1..4472d7c6ff40e8c758a47f836dcfe2976df74192 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2008 The OpenLDAP Foundation.
+ * Copyright 1998-2010 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -213,7 +213,7 @@ attr_dup2( Attribute *tmp, Attribute *a )
 {
        tmp->a_flags = a->a_flags & SLAP_ATTR_PERSISTENT_FLAGS;
        if ( a->a_vals != NULL ) {
-               int     i;
+               unsigned        i, j;
 
                tmp->a_numvals = a->a_numvals;
                tmp->a_vals = ch_malloc( (tmp->a_numvals + 1) * sizeof(struct berval) );
@@ -228,7 +228,6 @@ attr_dup2( Attribute *tmp, Attribute *a )
                assert( a->a_nvals != NULL );
 
                if ( a->a_nvals != a->a_vals ) {
-                       int     j;
 
                        tmp->a_nvals = ch_malloc( (tmp->a_numvals + 1) * sizeof(struct berval) );
                        for ( j = 0; !BER_BVISNULL( &a->a_nvals[j] ); j++ ) {
@@ -294,7 +293,7 @@ attr_valfind(
        MatchingRule *mr;
        const char *text;
        int match = -1, rc;
-       unsigned i;
+       unsigned i, n;
 
        if ( flags & SLAP_MR_ORDERING )
                mr = a->a_desc->ad_type->sat_ordering;
@@ -317,11 +316,12 @@ attr_valfind(
                cval = val;
        }
 
-       if ( a->a_flags & SLAP_ATTR_SORTED_VALS ) {
+       n = a->a_numvals;
+       if ( (a->a_flags & SLAP_ATTR_SORTED_VALS) && n ) {
                /* Binary search */
-               unsigned base = 0, n = a->a_numvals;
+               unsigned base = 0;
 
-               while ( 0 < n ) {
+               do {
                        unsigned pivot = n >> 1;
                        i = base + pivot;
                        rc = value_match( &match, a->a_desc, mr, flags,
@@ -334,12 +334,12 @@ attr_valfind(
                        } else {
                                n = pivot;
                        }
-               }
+               } while ( n );
                if ( match < 0 )
                        i++;
        } else {
        /* Linear search */
-               for ( i = 0; i < a->a_numvals; i++ ) {
+               for ( i = 0; i < n; i++ ) {
                        const char *text;
 
                        rc = ordered_value_match( &match, a->a_desc, mr, flags,
@@ -348,10 +348,10 @@ attr_valfind(
                                break;
                }
        }
-       if ( slot )
-               *slot = i;
        if ( match )
                rc = LDAP_NO_SUCH_ATTRIBUTE;
+       if ( slot )
+               *slot = i;
        if ( nval.bv_val )
                slap_sl_free( nval.bv_val, ctx );
 
@@ -404,7 +404,7 @@ attr_valadd(
                                        rc = LDAP_TYPE_OR_VALUE_EXISTS;
                                return rc;
                        }
-                       for ( j = a->a_numvals; j >= slot; j-- ) {
+                       for ( j = a->a_numvals; j >= (int)slot; j-- ) {
                                a->a_vals[j+1] = a->a_vals[j];
                                if ( nvals )
                                        a->a_nvals[j+1] = a->a_nvals[j];