summaryrefslogtreecommitdiffstats
path: root/server/util
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/util
parent6fe2bfce9fb9bb1564be8257cccc52bcec589de4 (diff)
downloadsssd-11c415db488265450163b414316cc3b9def17238.tar.gz
sssd-11c415db488265450163b414316cc3b9def17238.tar.xz
sssd-11c415db488265450163b414316cc3b9def17238.zip
Initial memory cleanup work
Diffstat (limited to 'server/util')
-rw-r--r--server/util/memory.c26
-rw-r--r--server/util/util.h4
2 files changed, 30 insertions, 0 deletions
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__ */