From 69fa2d9f93d7e6683d200ab4156c281d6475b5cd Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Fri, 18 Aug 2006 23:54:24 +0000 Subject: [PATCH] Move ber_sockbuf_free() to slapd_remove() to avoid using AC_SOCKET_INVALID --- servers/slapd/connection.c | 18 +++++------------- servers/slapd/daemon.c | 3 ++- servers/slapd/proto-slap.h | 4 ++-- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index e9e60db17c..16433b2533 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -653,7 +653,7 @@ void connection2anonymous( Connection *c ) static void connection_destroy( Connection *c ) { - ber_socket_t sd, inval = AC_SOCKET_INVALID; + ber_socket_t sd; unsigned long connid; const char *close_reason; Sockbuf *sb; @@ -731,23 +731,17 @@ connection_destroy( Connection *c ) } ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, &sd ); - slapd_sd_lock(); - - ber_sockbuf_ctrl( sb, LBER_SB_OPT_SET_FD, &inval ); - ber_sockbuf_free( sb ); /* c must be fully reset by this point; when we call slapd_remove * it may get immediately reused by a new connection. */ if ( sd != AC_SOCKET_INVALID ) { - slapd_remove( sd, 1, 0, 1 ); + slapd_remove( sd, sb, 1, 0, 0 ); Statslog( LDAP_DEBUG_STATS, (close_reason ? "conn=%lu fd=%ld closed (%s)\n" : "conn=%lu fd=%ld closed\n"), connid, (long) sd, close_reason, 0, 0 ); - } else { - slapd_sd_unlock(); } } @@ -1219,7 +1213,7 @@ void connection_client_stop( ber_socket_t s ) { Connection *c; - ber_socket_t inval = AC_SOCKET_INVALID; + Sockbuf *sb; /* get (locked) connection */ c = connection_get( s ); @@ -1230,15 +1224,13 @@ void connection_client_stop( c->c_conn_state = SLAP_C_INVALID; c->c_struct_state = SLAP_C_UNUSED; c->c_close_reason = "?"; /* should never be needed */ - slapd_sd_lock(); - ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_FD, &inval ); - ber_sockbuf_free( c->c_sb ); - slapd_remove( s, 0, 1, 1 ); + sb = c->c_sb; c->c_sb = ber_sockbuf_alloc( ); { ber_len_t max = sockbuf_max_incoming; ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max ); } + slapd_remove( s, sb, 0, 1, 0 ); connection_return( c ); } diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index b84d7c5caa..7e8dca9508 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -501,6 +501,7 @@ void slapd_sd_unlock() */ void slapd_remove( ber_socket_t s, + Sockbuf *sb, int wasactive, int wake, int locked ) @@ -527,7 +528,7 @@ void slapd_remove( SLAP_DEL_SOCK(s); - tcp_close(s); + ber_sockbuf_free(sb); /* If we ran out of file descriptors, we dropped a listener from * the select() loop. Now that we're removing a session from our diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 99934a9f80..640fc982ce 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -713,8 +713,8 @@ LDAP_SLAPD_F (int) slapd_daemon_init( const char *urls ); LDAP_SLAPD_F (int) slapd_daemon_destroy(void); LDAP_SLAPD_F (int) slapd_daemon(void); LDAP_SLAPD_F (Listener **) slapd_get_listeners LDAP_P((void)); -LDAP_SLAPD_F (void) slapd_remove LDAP_P((ber_socket_t s, int wasactive, - int wake, int locked )); +LDAP_SLAPD_F (void) slapd_remove LDAP_P((ber_socket_t s, Sockbuf *sb, + int wasactive, int wake, int locked )); LDAP_SLAPD_F (void) slapd_sd_lock(); LDAP_SLAPD_F (void) slapd_sd_unlock(); -- 2.39.5