From 6bbca5e3684f6fe538e5fdfb51c1ae36eccc4d58 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Tue, 23 Nov 2004 14:42:04 +0000 Subject: [PATCH] Now that we have a fixed number of slots for controls, don't bother realloc'ing slap_known_controls. --- servers/slapd/controls.c | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/servers/slapd/controls.c b/servers/slapd/controls.c index ecdc8fe835..dccb75fbfb 100644 --- a/servers/slapd/controls.c +++ b/servers/slapd/controls.c @@ -75,7 +75,7 @@ static LDAP_SLIST_HEAD(ControlsList, slap_control) controls_list /* * all known request control OIDs should be added to this list */ -char **slap_known_controls = NULL; +char *slap_known_controls[SLAP_MAX_CIDS+1]; static int num_known_controls; static char *proxy_authz_extops[] = { @@ -175,6 +175,13 @@ register_supported_control(const char *controloid, { struct slap_control *sc; + if ( num_known_controls >= SLAP_MAX_CIDS ) { + Debug( LDAP_DEBUG_ANY, "Too many controls registered." + " Recompile slapd with SLAP_MAX_CIDS defined > %d\n", + SLAP_MAX_CIDS, 0, 0 ); + return LDAP_OTHER; + } + if ( controloid == NULL ) return LDAP_PARAM_ERROR; sc = (struct slap_control *)SLAP_MALLOC( sizeof( *sc ) ); @@ -193,35 +200,11 @@ register_supported_control(const char *controloid, } sc->sc_parse = controlparsefn; - /* Update slap_known_controls, too. */ - if ( slap_known_controls == NULL ) { - slap_known_controls = (char **)SLAP_MALLOC( 2 * sizeof(char *) ); - if ( slap_known_controls == NULL ) { - if ( sc->sc_extendedops != NULL ) { - ldap_charray_free( sc->sc_extendedops ); - } - ch_free( sc ); - return LDAP_NO_MEMORY; - } - - } else { - char **new_known_controls; - - new_known_controls = (char **)SLAP_REALLOC( - slap_known_controls, (num_known_controls + 2) * sizeof(char *) ); - - if ( new_known_controls == NULL ) { - if ( sc->sc_extendedops != NULL ) { - ldap_charray_free( sc->sc_extendedops ); - } - ch_free( sc ); - return LDAP_NO_MEMORY; - } - slap_known_controls = new_known_controls; - } if ( controlcid ) *controlcid = num_known_controls; sc->sc_cid = num_known_controls; - slap_known_controls[num_known_controls++] = ch_strdup( sc->sc_oid ); + + /* Update slap_known_controls, too. */ + slap_known_controls[num_known_controls++] = sc->sc_oid; slap_known_controls[num_known_controls] = NULL; LDAP_SLIST_NEXT( sc, sc_next ) = NULL; @@ -269,7 +252,6 @@ controls_destroy( void ) } ch_free( sc ); } - ldap_charray_free( slap_known_controls ); } /* -- 2.39.5