summaryrefslogtreecommitdiff
path: root/source4/smbd
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-09-26 03:50:24 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:59:16 -0500
commit9a62dce0ac2dd751c9cc3b9906eec8c4fe7c51b7 (patch)
treea6fd92fd12aae07a2bab782feecd66b4369b61f7 /source4/smbd
parent764eddb69647681f784f343a122251ca1ecf62df (diff)
downloadsamba-9a62dce0ac2dd751c9cc3b9906eec8c4fe7c51b7.tar.gz
samba-9a62dce0ac2dd751c9cc3b9906eec8c4fe7c51b7.tar.bz2
samba-9a62dce0ac2dd751c9cc3b9906eec8c4fe7c51b7.zip
r2648: - use a destructor on struct server_connection to simplify the
connection termination cleanup, and to ensure that the event contexts are properly removed for every process model - gave auth_context the new talloc treatment, which removes another source of memory leaks. (This used to be commit 230e1cd777b0fba82dffcbd656cfa23c155d0560)
Diffstat (limited to 'source4/smbd')
-rw-r--r--source4/smbd/process_single.c10
-rw-r--r--source4/smbd/process_standard.c10
-rw-r--r--source4/smbd/process_thread.c12
-rw-r--r--source4/smbd/service.c37
4 files changed, 28 insertions, 41 deletions
diff --git a/source4/smbd/process_single.c b/source4/smbd/process_single.c
index 62d780277c..12a265b62f 100644
--- a/source4/smbd/process_single.c
+++ b/source4/smbd/process_single.c
@@ -71,15 +71,7 @@ static void single_terminate_connection(struct server_connection *conn, const ch
DEBUG(2,("single_terminate_connection: reason[%s]\n",reason));
if (conn) {
- if (conn->service) {
- conn->service->ops->close_connection(conn,reason);
- }
-
- if (conn->server_socket) {
- DLIST_REMOVE(conn->server_socket->connection_list,conn);
- }
-
- server_destroy_connection(conn);
+ talloc_free(conn);
}
}
diff --git a/source4/smbd/process_standard.c b/source4/smbd/process_standard.c
index 1bb30c2ef0..194c6d24cc 100644
--- a/source4/smbd/process_standard.c
+++ b/source4/smbd/process_standard.c
@@ -94,15 +94,7 @@ static void standard_terminate_connection(struct server_connection *conn, const
DEBUG(2,("single_terminate_connection: reason[%s]\n",reason));
if (conn) {
- if (conn->service) {
- conn->service->ops->close_connection(conn,reason);
- }
-
- if (conn->server_socket) {
- DLIST_REMOVE(conn->server_socket->connection_list,conn);
- }
-
- server_destroy_connection(conn);
+ talloc_free(conn->service->srv_ctx);
}
/* terminate this process */
diff --git a/source4/smbd/process_thread.c b/source4/smbd/process_thread.c
index 4e11137f37..55688f85e8 100644
--- a/source4/smbd/process_thread.c
+++ b/source4/smbd/process_thread.c
@@ -117,17 +117,7 @@ static void thread_terminate_connection(struct server_connection *conn, const ch
DEBUG(0,("thread_terminate_connection: reason[%s]\n",reason));
if (conn) {
- if (conn->service) {
- conn->service->ops->close_connection(conn,reason);
- }
-
- if (conn->server_socket) {
- MUTEX_LOCK_BY_ID(MUTEX_SMBD);
- DLIST_REMOVE(conn->server_socket->connection_list,conn);
- MUTEX_UNLOCK_BY_ID(MUTEX_SMBD);
- }
-
- server_destroy_connection(conn);
+ talloc_free(conn);
}
/* terminate this thread */
diff --git a/source4/smbd/service.c b/source4/smbd/service.c
index e3eb4a02c1..1f6033c238 100644
--- a/source4/smbd/service.c
+++ b/source4/smbd/service.c
@@ -172,6 +172,29 @@ struct server_socket *service_setup_socket(struct server_service *service,
return srv_sock;
}
+/*
+ destructor that handles necessary event context changes
+ */
+static int server_destructor(void *ptr)
+{
+ struct server_connection *conn = ptr;
+
+ if (conn->service) {
+ conn->service->ops->close_connection(conn, "shutdown");
+ }
+
+ socket_destroy(conn->socket);
+
+ event_remove_fd(conn->event.ctx, conn->event.fde);
+ conn->event.fde = NULL;
+ event_remove_timed(conn->event.ctx, conn->event.idle);
+ conn->event.idle = NULL;
+
+ DLIST_REMOVE(conn->server_socket->connection_list, conn);
+
+ return 0;
+}
+
struct server_connection *server_setup_connection(struct event_context *ev,
struct server_socket *server_socket,
struct socket_context *sock,
@@ -215,6 +238,8 @@ struct server_connection *server_setup_connection(struct event_context *ev,
srv_conn->event.fde = event_add_fd(ev,&fde);
srv_conn->event.idle = event_add_timed(ev,&idle);
+ talloc_set_destructor(srv_conn, server_destructor);
+
if (!socket_check_access(sock, "smbd", lp_hostsallow(-1), lp_hostsdeny(-1))) {
server_terminate_connection(srv_conn, "denied by access rules");
return NULL;
@@ -232,18 +257,6 @@ void server_terminate_connection(struct server_connection *srv_conn, const char
srv_conn->service->model_ops->terminate_connection(srv_conn, reason);
}
-void server_destroy_connection(struct server_connection *srv_conn)
-{
- socket_destroy(srv_conn->socket);
-
- event_remove_fd(srv_conn->event.ctx, srv_conn->event.fde);
- srv_conn->event.fde = NULL;
- event_remove_timed(srv_conn->event.ctx, srv_conn->event.idle);
- srv_conn->event.idle = NULL;
-
- talloc_free(srv_conn);
-}
-
void server_io_handler(struct event_context *ev, struct fd_event *fde, time_t t, uint16_t flags)
{
struct server_connection *conn = fde->private;