summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2008-10-28 09:15:33 -0400
committerSimo Sorce <idra@samba.org>2008-11-03 10:12:29 -0500
commit11c415db488265450163b414316cc3b9def17238 (patch)
tree4b9b7c84057149cca95302f3ad9a1685bc14d5f2 /server
parent6fe2bfce9fb9bb1564be8257cccc52bcec589de4 (diff)
downloadsssd-11c415db488265450163b414316cc3b9def17238.tar.gz
sssd-11c415db488265450163b414316cc3b9def17238.tar.xz
sssd-11c415db488265450163b414316cc3b9def17238.zip
Initial memory cleanup work
Diffstat (limited to 'server')
-rw-r--r--server/dbus/sssd_dbus.h2
-rw-r--r--server/dbus/sssd_dbus_common.c3
-rw-r--r--server/dbus/sssd_dbus_connection.c2
-rw-r--r--server/dbus/sssd_dbus_server.c38
-rw-r--r--server/monitor.c5
-rw-r--r--server/server.mk1
-rw-r--r--server/util/memory.c26
-rw-r--r--server/util/util.h4
8 files changed, 71 insertions, 10 deletions
diff --git a/server/dbus/sssd_dbus.h b/server/dbus/sssd_dbus.h
index 00a665bc1..19c05ff55 100644
--- a/server/dbus/sssd_dbus.h
+++ b/server/dbus/sssd_dbus.h
@@ -43,6 +43,4 @@ int sssd_new_dbus_server(struct sssd_dbus_ctx *ctx, const char *address);
/* Connection Functions */
int sssd_new_dbus_connection(struct sssd_dbus_ctx *ctx, const char *address,
DBusConnection **connection);
-
-
#endif /* _SSSD_DBUS_H_*/
diff --git a/server/dbus/sssd_dbus_common.c b/server/dbus/sssd_dbus_common.c
index 188192ddd..a7f2bff2f 100644
--- a/server/dbus/sssd_dbus_common.c
+++ b/server/dbus/sssd_dbus_common.c
@@ -1,6 +1,7 @@
#include <sys/time.h>
#include "events.h"
#include "dbus/dbus.h"
+#include "util/util.h"
struct timeval _dbus_timeout_get_interval_tv(int interval) {
struct timeval tv;
@@ -20,6 +21,8 @@ struct timeval _dbus_timeout_get_interval_tv(int interval) {
*/
void remove_watch(DBusWatch *watch, void *data) {
struct fd_event *fde;
+
+ DEBUG(2, ("%lX\n", watch));
fde = talloc_get_type(dbus_watch_get_data(watch), struct fd_event);
/* Freeing the event object will remove it from the event loop */
diff --git a/server/dbus/sssd_dbus_connection.c b/server/dbus/sssd_dbus_connection.c
index f1675ff31..d5bd28ffd 100644
--- a/server/dbus/sssd_dbus_connection.c
+++ b/server/dbus/sssd_dbus_connection.c
@@ -112,6 +112,8 @@ static dbus_bool_t add_connection_watch(DBusWatch *watch, void *data)
if (event_flags == 0)
return FALSE;
+
+ DEBUG(2,("%lX: %d, %d=%s\n", watch, conn_w_ctx->fd, event_flags, event_flags==EVENT_FD_READ?"READ":"WRITE"));
/* Add the file descriptor to the event loop */
conn_w_ctx->fde = event_add_fd(conn_w_ctx->top->ev, conn_w_ctx,
diff --git a/server/dbus/sssd_dbus_server.c b/server/dbus/sssd_dbus_server.c
index 113866fa6..6ad8e0dd5 100644
--- a/server/dbus/sssd_dbus_server.c
+++ b/server/dbus/sssd_dbus_server.c
@@ -28,6 +28,8 @@
/* Types */
struct dbus_server_toplevel_context {
DBusServer *server;
+ /* talloc context to manage the server object memory*/
+ DBusServer **server_talloc;
struct sssd_dbus_ctx *sd_ctx;
};
@@ -44,6 +46,18 @@ struct dbus_server_timeout_context {
struct dbus_server_toplevel_context *top;
};
+static int dbus_server_destructor(void **server);
+
+void remove_server_watch(DBusWatch *watch, void *data) {
+ struct fd_event *fde;
+
+ DEBUG(2, ("%lX\n", watch));
+ fde = talloc_get_type(dbus_watch_get_data(watch), struct fd_event);
+
+ /* Freeing the event object will remove it from the event loop */
+ talloc_free(fde);
+}
+
/*
* dbus_server_read_write_handler
* Callback for D-BUS to handle messages on a file-descriptor
@@ -99,6 +113,7 @@ static dbus_bool_t add_server_watch(DBusWatch *watch, void *data)
if (flags & DBUS_WATCH_WRITABLE) {
event_flags |= EVENT_FD_WRITE;
}
+ DEBUG(2,("%lX: %d, %d=%s\n", watch, svw_ctx->fd, event_flags, event_flags==EVENT_FD_READ?"READ":"WRITE"));
svw_ctx->fde = event_add_fd(dt_ctx->sd_ctx->ev, svw_ctx, svw_ctx->fd,
event_flags, dbus_server_read_write_handler,
@@ -272,6 +287,7 @@ int sssd_new_dbus_server(struct sssd_dbus_ctx *ctx, const char *address)
{
struct dbus_server_toplevel_context *dt_ctx;
DBusServer *dbus_server;
+ DBusServer **dbus_server_talloc;
DBusError dbus_error;
dbus_bool_t dbret;
@@ -283,32 +299,33 @@ int sssd_new_dbus_server(struct sssd_dbus_ctx *ctx, const char *address)
dbus_error.name, dbus_error.message));
return EIO;
}
+ dbus_server_talloc = talloc_takeover(ctx, dbus_server, dbus_server_destructor);
- /* TODO: remove debug */
DEBUG(2, ("D-BUS Server listening on %s\n",
dbus_server_get_address(dbus_server)));
dt_ctx = talloc_zero(ctx, struct dbus_server_toplevel_context);
if (!dt_ctx) {
- /* FIXME: free DBusServer resources */
+ talloc_free(dbus_server_talloc);
return ENOMEM;
}
- dt_ctx->server = dbus_server;
+ dt_ctx->server_talloc = dbus_server_talloc;
+ dt_ctx->server = *dbus_server_talloc;
dt_ctx->sd_ctx = ctx;
/* Set up D-BUS new connection handler */
- /* FIXME: set free_data_function */
dbus_server_set_new_connection_function(dt_ctx->server,
new_connection_callback,
dt_ctx, NULL);
/* Set up DBusWatch functions */
dbret = dbus_server_set_watch_functions(dt_ctx->server, add_server_watch,
- remove_watch, toggle_server_watch,
+ remove_server_watch, toggle_server_watch,
dt_ctx, NULL);
if (!dbret) {
DEBUG(0, ("Error setting up D-BUS server watch functions"));
- /* FIXME: free DBusServer resources */
+ talloc_free(dt_ctx->server_talloc);
+ dt_ctx->server = NULL;
return EIO;
}
@@ -320,9 +337,16 @@ int sssd_new_dbus_server(struct sssd_dbus_ctx *ctx, const char *address)
dt_ctx, NULL);
if (!dbret) {
DEBUG(0,("Error setting up D-BUS server timeout functions"));
- /* FIXME: free DBusServer resources */
+ dbus_server_set_watch_functions(dt_ctx->server, NULL, NULL, NULL, NULL, NULL);
+ talloc_free(dt_ctx->server_talloc);
+ dt_ctx->server = NULL;
return EIO;
}
return EOK;
}
+
+static int dbus_server_destructor(void **server) {
+ dbus_server_disconnect(*server);
+ return 0;
+}
diff --git a/server/monitor.c b/server/monitor.c
index 0f92eceb4..b11e4e0c9 100644
--- a/server/monitor.c
+++ b/server/monitor.c
@@ -207,7 +207,10 @@ int start_monitor(TALLOC_CTX *mem_ctx,
/* Initialize D-BUS Server
* The monitor will act as a D-BUS server for all
* SSSD processes */
- monitor_dbus_init(ctx);
+ ret = monitor_dbus_init(ctx);
+ if (ret != EOK) {
+ return ret;
+ }
for (i = 0; ctx->services[i]; i++) {
diff --git a/server/server.mk b/server/server.mk
index f49a7b041..a65dcb582 100644
--- a/server/server.mk
+++ b/server/server.mk
@@ -7,6 +7,7 @@ SERVER_OBJ = \
util/debug.o \
util/signal.o \
util/become_daemon.o \
+ util/memory.o \
confdb/confdb.o \
nss/nsssrv.o \
nss/nsssrv_packet.o \
diff --git a/server/util/memory.c b/server/util/memory.c
new file mode 100644
index 000000000..e73fd0169
--- /dev/null
+++ b/server/util/memory.c
@@ -0,0 +1,26 @@
+#include "util/util.h"
+
+/*
+ * talloc_takeover
+ * This function will take a non-talloc pointer and add it to a talloc
+ * memory context. It will accept a destructor for the original pointer
+ * so that when the parent memory context is freed, the non-talloc
+ * pointer will also be freed properly.
+ */
+TALLOC_CTX *talloc_takeover(TALLOC_CTX *mem_ctx, void *ptr, int (*destructor)(void **)) {
+ void **handle;
+
+ if (ptr == NULL) {
+ return NULL;
+ }
+
+ handle = talloc_named_const(mem_ctx, sizeof(void *), "void *");
+ if (handle == NULL) {
+ return NULL;
+ }
+
+ *handle = ptr;
+ talloc_set_destructor(handle,destructor);
+
+ return handle;
+} \ No newline at end of file
diff --git a/server/util/util.h b/server/util/util.h
index 05113d1fb..1613c9efe 100644
--- a/server/util/util.h
+++ b/server/util/util.h
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdbool.h>
#include "replace.h"
+#include "talloc.h"
extern int debug_level;
void debug_fn(const char *format, ...);
@@ -42,4 +43,7 @@ void (*CatchSignal(int signum,void (*handler)(int )))(int);
void CatchChild(void);
void CatchChildLeaveStatus(void);
+/* from memory.c */
+//TALLOC_CTX *talloc_takeover(TALLOC_CTX *mem_ctx, void *ptr, int (*destructor)(void *), const char *type);
+TALLOC_CTX *talloc_takeover(TALLOC_CTX *mem_ctx, void *ptr, int (*destructor)(void **));
#endif /* __SSSD_UTIL_H__ */