Clean up events properly

This commit is contained in:
Ondřej Kuzník 2017-05-09 18:02:28 +01:00 committed by Ondřej Kuzník
parent 8eb7f3fbca
commit 9ebe5acb62
2 changed files with 20 additions and 8 deletions

View file

@ -278,12 +278,12 @@ client_init(
return c;
fail:
if ( c->c_write_event ) {
event_del( c->c_write_event );
event_free( c->c_write_event );
c->c_write_event = NULL;
}
if ( c->c_read_event ) {
event_del( c->c_read_event );
event_free( c->c_read_event );
c->c_read_event = NULL;
}
c->c_state = SLAP_C_INVALID;
connection_destroy( c );
@ -298,13 +298,13 @@ client_destroy( Connection *c )
c->c_connid );
if ( c->c_read_event ) {
event_del( c->c_read_event );
event_free( c->c_read_event );
c->c_read_event = NULL;
}
if ( c->c_write_event ) {
event_del( c->c_write_event );
event_free( c->c_write_event );
c->c_write_event = NULL;
}
c->c_state = SLAP_C_INVALID;

View file

@ -870,11 +870,13 @@ upstream_destroy( Connection *c )
* event_del will block if the event is currently executing its callback,
* that callback might be waiting to lock c->c_mutex
*/
event_del( read_event );
event_free( read_event );
if ( read_event ) {
event_del( read_event );
}
event_del( write_event );
event_free( write_event );
if ( write_event ) {
event_del( write_event );
}
ldap_pvt_thread_mutex_lock( &b->b_mutex );
LDAP_LIST_REMOVE( c, c_next );
@ -889,6 +891,16 @@ upstream_destroy( Connection *c )
CONNECTION_LOCK_DECREF(c);
if ( c->c_read_event ) {
event_free( c->c_read_event );
c->c_read_event = NULL;
}
if ( c->c_write_event ) {
event_free( c->c_write_event );
c->c_write_event = NULL;
}
/*
* If we attempted to destroy any operations, we might have lent a new
* refcnt token for a thread that raced us to that, let them call us again