summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/socket/socket.c32
-rw-r--r--source4/lib/time.c2
2 files changed, 27 insertions, 7 deletions
diff --git a/source4/lib/socket/socket.c b/source4/lib/socket/socket.c
index 4814cc6a5a..4fde41a3c0 100644
--- a/source4/lib/socket/socket.c
+++ b/source4/lib/socket/socket.c
@@ -20,6 +20,18 @@
#include "includes.h"
+/*
+ auto-close sockets on free
+*/
+static int socket_destructor(void *ptr)
+{
+ struct socket_context *sock = ptr;
+ if (sock->ops->close) {
+ sock->ops->close(sock);
+ }
+ return 0;
+}
+
NTSTATUS socket_create(const char *name, enum socket_type type, struct socket_context **new_sock, uint32_t flags)
{
NTSTATUS status;
@@ -38,24 +50,24 @@ NTSTATUS socket_create(const char *name, enum socket_type type, struct socket_co
(*new_sock)->private_data = NULL;
(*new_sock)->ops = socket_getops_byname(name, type);
if (!(*new_sock)->ops) {
- talloc_free((*new_sock));
+ talloc_free(*new_sock);
return NT_STATUS_INVALID_PARAMETER;
}
status = (*new_sock)->ops->init((*new_sock));
if (!NT_STATUS_IS_OK(status)) {
- talloc_free((*new_sock));
+ talloc_free(*new_sock);
return status;
}
+ talloc_set_destructor(*new_sock, socket_destructor);
+
return NT_STATUS_OK;
}
void socket_destroy(struct socket_context *sock)
{
- if (sock->ops->close) {
- sock->ops->close(sock);
- }
+ /* the close is handled by the destructor */
talloc_free(sock);
}
@@ -98,6 +110,8 @@ NTSTATUS socket_listen(struct socket_context *sock, const char *my_address, int
NTSTATUS socket_accept(struct socket_context *sock, struct socket_context **new_sock, uint32_t flags)
{
+ NTSTATUS status;
+
if (sock->type != SOCKET_TYPE_STREAM) {
return NT_STATUS_INVALID_PARAMETER;
}
@@ -110,7 +124,13 @@ NTSTATUS socket_accept(struct socket_context *sock, struct socket_context **new_
return NT_STATUS_NOT_IMPLEMENTED;
}
- return sock->ops->accept(sock, new_sock, flags);
+ status = sock->ops->accept(sock, new_sock, flags);
+
+ if (NT_STATUS_IS_OK(status)) {
+ talloc_set_destructor(*new_sock, socket_destructor);
+ }
+
+ return status;
}
NTSTATUS socket_recv(struct socket_context *sock, TALLOC_CTX *mem_ctx,
diff --git a/source4/lib/time.c b/source4/lib/time.c
index bd8d7ddb30..fec4dd62a2 100644
--- a/source4/lib/time.c
+++ b/source4/lib/time.c
@@ -137,7 +137,7 @@ void unix_to_nt_time(NTTIME *nt, time_t t)
/****************************************************************************
check if it's a null mtime
****************************************************************************/
-BOOL null_mtime(time_t mtime)
+static BOOL null_mtime(time_t mtime)
{
return mtime == 0 ||
mtime == (time_t)0xFFFFFFFF ||