Commit 9bf50242 authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

Plug ber leakage:

result was leaking ber's in some error cases.  ber_flush now called
with no freeing so that caller of send_ldap_ber() can free its own ber.
c->c_currentber was also being leaked if connection was destory
current when a PDU input was outstanding.
Fixed ber_flush to free ber upon write only to file.
parent 2330f146
......@@ -240,6 +240,8 @@ ber_flush( Sockbuf *sb, BerElement *ber, int freeit )
if ( sb->sb_options & (LBER_TO_FILE | LBER_TO_FILE_ONLY) ) {
rc = write( sb->sb_fd, ber->ber_rwptr, towrite );
if ( sb->sb_options & LBER_TO_FILE_ONLY ) {
if ( freeit )
ber_free( ber, 1 );
return( (int)rc );
}
}
......
......@@ -370,6 +370,7 @@ long connection_init(
#endif
c->c_sb = ber_sockbuf_alloc( );
c->c_currentber = NULL;
/* should check status of thread calls */
ldap_pvt_thread_mutex_init( &c->c_mutex );
......@@ -395,6 +396,7 @@ long connection_init(
#ifdef HAVE_CYRUS_SASL
assert( c->c_sasl_context == NULL );
#endif
assert( c->c_currentber == NULL );
c->c_listener_url = ch_strdup( url );
c->c_peer_domain = ch_strdup( dnsname );
......@@ -502,6 +504,11 @@ connection_destroy( Connection *c )
}
#endif
if ( c->c_currentber != NULL ) {
ber_free( c->c_currentber, 1 );
c->c_currentber = NULL;
}
if ( ber_pvt_sb_in_use(c->c_sb) ) {
int sd = ber_pvt_sb_get_desc(c->c_sb);
......
......@@ -169,10 +169,11 @@ static long send_ldap_ber(
if ( connection_state_closing( conn ) ) {
ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
return 0;
}
if ( ber_flush( conn->c_sb, ber, 1 ) == 0 ) {
if ( ber_flush( conn->c_sb, ber, 0 ) == 0 ) {
break;
}
......@@ -193,6 +194,7 @@ static long send_ldap_ber(
ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
return( -1 );
}
......@@ -273,11 +275,13 @@ send_ldap_response(
if ( rc == -1 ) {
Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
ber_free( ber, 1 );
return;
}
/* send BER */
bytes = send_ldap_ber( conn, ber );
ber_free( ber, 1 );
if ( bytes < 0 ) {
Debug( LDAP_DEBUG_ANY,
......@@ -702,6 +706,7 @@ send_search_entry(
}
bytes = send_ldap_ber( conn, ber );
ber_free( ber, 1 );
if ( bytes < 0 ) {
Debug( LDAP_DEBUG_ANY,
......@@ -801,6 +806,7 @@ send_search_reference(
}
bytes = send_ldap_ber( conn, ber );
ber_free( ber, 1 );
ldap_pvt_thread_mutex_lock( &num_sent_mutex );
num_bytes_sent += bytes;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment