diff --git a/src/piler-smtp.c b/src/piler-smtp.c index f52f126..f44e041 100644 --- a/src/piler-smtp.c +++ b/src/piler-smtp.c @@ -94,7 +94,7 @@ for(int i=0; ilasttime >= cfg.smtp_timeout){ syslog(LOG_PRIORITY, "client %s timeout, lasttime: %ld", sessions[i]->remote_host, sessions[i]->lasttime); - tear_down_session(sessions, sessions[i]->slot, &num_connections); + tear_down_session(sessions, sessions[i]->slot, &num_connections, "timeout"); } } } @@ -232,7 +232,7 @@ if(cfg.verbosity >= _LOG_EXTREME) syslog(LOG_PRIORITY, "ERROR: the remote end hung up without sending QUIT"); session = get_session_by_socket(sessions, cfg.max_connections, events[i].data.fd); if(session) - tear_down_session(sessions, session->slot, &num_connections); + tear_down_session(sessions, session->slot, &num_connections, "hungup"); else close(events[i].data.fd); continue; @@ -333,7 +333,7 @@ /* Don't wait until the remote client closes the connection after he sent the QUIT command */ if(done || session->protocol_state == SMTP_STATE_FINISHED){ - tear_down_session(sessions, session->slot, &num_connections); + tear_down_session(sessions, session->slot, &num_connections, "done"); } } diff --git a/src/piler.h b/src/piler.h index a38be51..c33ff60 100644 --- a/src/piler.h +++ b/src/piler.h @@ -70,7 +70,7 @@ int is_email_address_on_my_domains(char *email, struct data *data); int start_new_session(struct smtp_session **sessions, int socket, int *num_connections, struct smtp_acl *smtp_acl[], char *client_addr, struct config *cfg); -void tear_down_session(struct smtp_session **sessions, int slot, int *num_connections); +void tear_down_session(struct smtp_session **sessions, int slot, int *num_connections, char *reason); struct smtp_session *get_session_by_socket(struct smtp_session **sessions, int max_connections, int socket); void write_envelope_addresses(struct smtp_session *session, struct config *cfg); void handle_data(struct smtp_session *session, char *readbuf, int readlen, struct config *cfg); diff --git a/src/session.c b/src/session.c index b527323..80fa0a4 100644 --- a/src/session.c +++ b/src/session.c @@ -118,28 +118,38 @@ void free_smtp_session(struct smtp_session *session){ - if(session){ + syslog(LOG_PRIORITY, "free_smtp_session()"); if(session->net.use_ssl == 1){ + syslog(LOG_PRIORITY, "SSL_shutdown()"); SSL_shutdown(session->net.ssl); SSL_free(session->net.ssl); + syslog(LOG_PRIORITY, "SSL_free()"); } - if(session->net.ctx) SSL_CTX_free(session->net.ctx); + if(session->net.ctx){ + syslog(LOG_PRIORITY, "SSL_CTX_free"); + SSL_CTX_free(session->net.ctx); + } + syslog(LOG_PRIORITY, "freeing session"); free(session); + syslog(LOG_PRIORITY, "free(session) done"); } } -void tear_down_session(struct smtp_session **sessions, int slot, int *num_connections){ +void tear_down_session(struct smtp_session **sessions, int slot, int *num_connections, char *reason){ if(sessions[slot] == NULL){ - syslog(LOG_PRIORITY, "session already torn down, slot=%d (%d active connections)", slot, *num_connections); + syslog(LOG_PRIORITY, "session already torn down, slot=%d, reason=%s (%d active connections)", slot, reason, *num_connections); return; } - syslog(LOG_PRIORITY, "disconnected from %s on fd=%d, slot=%d (%d active connections)", sessions[slot]->remote_host, sessions[slot]->net.socket, slot, (*num_connections)-1); + if(*num_connections > 0) (*num_connections)--; + + syslog(LOG_PRIORITY, "disconnected from %s on fd=%d, slot=%d, reason=%s (%d active connections)", + sessions[slot]->remote_host, sessions[slot]->net.socket, slot, reason, *num_connections); close(sessions[slot]->net.socket); @@ -152,8 +162,6 @@ free_smtp_session(sessions[slot]); sessions[slot] = NULL; - - if(*num_connections > 0) (*num_connections)--; }