summaryrefslogtreecommitdiff
path: root/source4/smbd/service.c
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/service.c
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/service.c')
-rw-r--r--source4/smbd/service.c37
1 files changed, 25 insertions, 12 deletions
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;