From: Howard Chu Date: Mon, 31 Dec 2001 06:02:35 +0000 (+0000) Subject: Use ber_free_buf X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~398 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=9383bf326511a182c8547e340f22aa4ff2632597;p=openldap Use ber_free_buf --- diff --git a/servers/slapd/passwd.c b/servers/slapd/passwd.c index 143cd2f31e..4a9e49ecc7 100644 --- a/servers/slapd/passwd.c +++ b/servers/slapd/passwd.c @@ -239,8 +239,10 @@ struct berval * slap_passwd_return( struct berval *cred ) { int rc; - struct berval *bv; - BerElement *ber = ber_alloc_t(LBER_USE_DER); + struct berval *bv = NULL; + char berbuf[256]; + /* opaque structure, size unknown but smaller than berbuf */ + BerElement *ber = (BerElement *)berbuf; assert( cred != NULL ); @@ -251,21 +253,17 @@ struct berval * slap_passwd_return( Debug( LDAP_DEBUG_TRACE, "slap_passwd_return: %ld\n", (long) cred->bv_len, 0, 0 ); #endif - - - if( ber == NULL ) return NULL; + ber_init_w_nullc( ber, LBER_USE_DER ); + rc = ber_printf( ber, "{tON}", LDAP_TAG_EXOP_X_MODIFY_PASSWD_GEN, cred ); - if( rc == -1 ) { - ber_free( ber, 1 ); - return NULL; + if( rc >= 0 ) { + (void) ber_flatten( ber, &bv ); } - (void) ber_flatten( ber, &bv ); - - ber_free( ber, 1 ); + ber_free_buf( ber, 1 ); return bv; } diff --git a/servers/slapd/result.c b/servers/slapd/result.c index a4017a0234..245ce38150 100644 --- a/servers/slapd/result.c +++ b/servers/slapd/result.c @@ -183,7 +183,8 @@ send_ldap_response( LDAPControl **ctrls ) { - BerElement *ber; + char berbuf[256]; + BerElement *ber = (BerElement *)berbuf; int rc; long bytes; @@ -195,7 +196,7 @@ send_ldap_response( assert( ctrls == NULL ); /* ctrls not implemented */ - ber = ber_alloc_t( LBER_USE_DER ); + ber_init_w_nullc( ber, LBER_USE_DER ); #ifdef NEW_LOGGING LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY, @@ -222,18 +223,6 @@ send_ldap_response( } - if ( ber == NULL ) { -#ifdef NEW_LOGGING - LDAP_LOG(( "operation", LDAP_LEVEL_ERR, - "send_ldap_response: conn %d ber_alloc failed\n", - conn ? conn->c_connid : 0 )); -#else - Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 ); -#endif - - return; - } - #ifdef LDAP_CONNECTIONLESS if (conn->c_is_udp) { rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0); @@ -245,7 +234,7 @@ send_ldap_response( #else Debug( LDAP_DEBUG_ANY, "ber_write failed\n", 0, 0, 0 ); #endif - ber_free(ber, 1); + ber_free_buf( ber ); return; } } @@ -306,13 +295,13 @@ send_ldap_response( Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 ); #endif - ber_free( ber, 1 ); + ber_free_buf( ber ); return; } /* send BER */ bytes = send_ldap_ber( conn, ber ); - ber_free( ber, 1 ); + ber_free_buf( ber ); if ( bytes < 0 ) { #ifdef NEW_LOGGING @@ -634,7 +623,8 @@ send_search_entry( LDAPControl **ctrls ) { - BerElement *ber; + char berbuf[256]; + BerElement *ber = (BerElement *)berbuf;; Attribute *a, *aa; int i, rc=-1, bytes; char *edn; @@ -673,21 +663,7 @@ send_search_entry( edn = e->e_ndn; - ber = ber_alloc_t( LBER_USE_DER ); - - if ( ber == NULL ) { -#ifdef NEW_LOGGING - LDAP_LOG(( "operation", LDAP_LEVEL_ERR, - "send_search_entry: conn %d ber_alloc failed\n", - op->o_connid )); -#else - Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 ); -#endif - - send_ldap_result( conn, op, LDAP_OTHER, - NULL, "BER allocation error", NULL, NULL ); - goto error_return; - } + ber_init_w_nullc( ber, LBER_USE_DER ); #ifdef LDAP_CONNECTIONLESS if (conn->c_is_udp) { @@ -700,7 +676,7 @@ send_search_entry( #else Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 ); #endif - ber_free(ber, 1); + ber_free_buf( ber ); return; } } @@ -723,7 +699,7 @@ send_search_entry( Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 ); #endif - ber_free( ber, 1 ); + ber_free_buf( ber ); send_ldap_result( conn, op, LDAP_OTHER, NULL, "encoding DN error", NULL, NULL ); goto error_return; @@ -783,7 +759,7 @@ send_search_entry( Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 ); #endif - ber_free( ber, 1 ); + ber_free_buf( ber ); send_ldap_result( conn, op, LDAP_OTHER, NULL, "encoding description error", NULL, NULL ); goto error_return; @@ -817,7 +793,7 @@ send_search_entry( "ber_printf failed\n", 0, 0, 0 ); #endif - ber_free( ber, 1 ); + ber_free_buf( ber ); send_ldap_result( conn, op, LDAP_OTHER, NULL, "encoding values error", NULL, NULL ); goto error_return; @@ -834,7 +810,7 @@ send_search_entry( Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 ); #endif - ber_free( ber, 1 ); + ber_free_buf( ber ); send_ldap_result( conn, op, LDAP_OTHER, NULL, "encode end error", NULL, NULL ); goto error_return; @@ -891,7 +867,7 @@ send_search_entry( Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 ); #endif - ber_free( ber, 1 ); + ber_free_buf( ber ); send_ldap_result( conn, op, LDAP_OTHER, NULL, "encoding description error", NULL, NULL ); attrs_free( aa ); @@ -927,7 +903,7 @@ send_search_entry( "ber_printf failed\n", 0, 0, 0 ); #endif - ber_free( ber, 1 ); + ber_free_buf( ber ); send_ldap_result( conn, op, LDAP_OTHER, NULL, "encoding values error", NULL, NULL ); attrs_free( aa ); @@ -945,7 +921,7 @@ send_search_entry( Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 ); #endif - ber_free( ber, 1 ); + ber_free_buf( ber ); send_ldap_result( conn, op, LDAP_OTHER, NULL, "encode end error", NULL, NULL ); attrs_free( aa ); @@ -970,14 +946,14 @@ send_search_entry( Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 ); #endif - ber_free( ber, 1 ); + ber_free_buf( ber ); send_ldap_result( conn, op, LDAP_OTHER, NULL, "encode entry end error", NULL, NULL ); return( 1 ); } bytes = send_ldap_ber( conn, ber ); - ber_free( ber, 1 ); + ber_free_buf( ber ); if ( bytes < 0 ) { #ifdef NEW_LOGGING @@ -1028,7 +1004,8 @@ send_search_reference( struct berval ***v2refs ) { - BerElement *ber; + char berbuf[256]; + BerElement *ber = (BerElement *)berbuf; int rc; int bytes; @@ -1100,22 +1077,7 @@ send_search_reference( return 0; } - ber = ber_alloc_t( LBER_USE_DER ); - - if ( ber == NULL ) { -#ifdef NEW_LOGGING - LDAP_LOG(( "operation", LDAP_LEVEL_ERR, - "send_search_reference: conn %d ber_alloc failed\n", - op->o_connid )); -#else - Debug( LDAP_DEBUG_ANY, - "send_search_reference: ber_alloc failed\n", 0, 0, 0 ); -#endif - - send_ldap_result( conn, op, LDAP_OTHER, - NULL, "alloc BER error", NULL, NULL ); - return -1; - } + ber_init_w_nullc( ber, LBER_USE_DER ); rc = ber_printf( ber, "{it{V}N}", op->o_msgid, LDAP_RES_SEARCH_REFERENCE, refs ); @@ -1130,14 +1092,14 @@ send_search_reference( "send_search_reference: ber_printf failed\n", 0, 0, 0 ); #endif - ber_free( ber, 1 ); + ber_free_buf( ber ); send_ldap_result( conn, op, LDAP_OTHER, NULL, "encode DN error", NULL, NULL ); return -1; } bytes = send_ldap_ber( conn, ber ); - ber_free( ber, 1 ); + ber_free_buf( ber ); ldap_pvt_thread_mutex_lock( &num_sent_mutex ); num_bytes_sent += bytes;