summaryrefslogtreecommitdiff
path: root/source3/lib/talloc
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2006-09-29 10:53:27 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:14:54 -0500
commit43be47f56bcaa2fd93ede867663cddec04fd8fed (patch)
tree2032aee6a9f03c1efaefbf7fdda14b6e20c8ce2f /source3/lib/talloc
parentda6c811eca4b03395bc76a34eaeaedf5566154ba (diff)
downloadsamba-43be47f56bcaa2fd93ede867663cddec04fd8fed.tar.gz
samba-43be47f56bcaa2fd93ede867663cddec04fd8fed.tar.bz2
samba-43be47f56bcaa2fd93ede867663cddec04fd8fed.zip
r18996: merge from samba4:
- fix bug 4078 - talloc_free(talloc_autofree_context()); should not result in a SIGABORT on exit - add a test for this, but this test can also pass in the standalone build and samba3, as samba4 uses talloc_autofree_context() metze (This used to be commit f5b0924f975f58bba3c13a53388ea25af51d3bc8)
Diffstat (limited to 'source3/lib/talloc')
-rw-r--r--source3/lib/talloc/talloc.c18
-rw-r--r--source3/lib/talloc/testsuite.c31
2 files changed, 37 insertions, 12 deletions
diff --git a/source3/lib/talloc/talloc.c b/source3/lib/talloc/talloc.c
index 58028a85b8..15b27c61ee 100644
--- a/source3/lib/talloc/talloc.c
+++ b/source3/lib/talloc/talloc.c
@@ -82,7 +82,7 @@
NULL
*/
static void *null_context;
-static void *cleanup_context;
+static void *autofree_context;
struct talloc_reference_handle {
struct talloc_reference_handle *next, *prev;
@@ -1208,10 +1208,15 @@ void *talloc_realloc_fn(const void *context, void *ptr, size_t size)
}
+static int talloc_autofree_destructor(void *ptr)
+{
+ autofree_context = NULL;
+ return 0;
+}
+
static void talloc_autofree(void)
{
- talloc_free(cleanup_context);
- cleanup_context = NULL;
+ talloc_free(autofree_context);
}
/*
@@ -1220,11 +1225,12 @@ static void talloc_autofree(void)
*/
void *talloc_autofree_context(void)
{
- if (cleanup_context == NULL) {
- cleanup_context = talloc_named_const(NULL, 0, "autofree_context");
+ if (autofree_context == NULL) {
+ autofree_context = talloc_named_const(NULL, 0, "autofree_context");
+ talloc_set_destructor(autofree_context, talloc_autofree_destructor);
atexit(talloc_autofree);
}
- return cleanup_context;
+ return autofree_context;
}
size_t talloc_get_size(const void *context)
diff --git a/source3/lib/talloc/testsuite.c b/source3/lib/talloc/testsuite.c
index 00ea212e58..70ee35cbef 100644
--- a/source3/lib/talloc/testsuite.c
+++ b/source3/lib/talloc/testsuite.c
@@ -24,10 +24,6 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifdef _SAMBA_BUILD_
-#include "version.h"
-#endif /* _SAMBA_BUILD_ */
-
#include "replace.h"
#include "system/time.h"
#include "talloc.h"
@@ -48,7 +44,7 @@ static double timeval_elapsed(struct timeval *tv)
(tv2.tv_usec - tv->tv_usec)*1.0e-6;
}
-#if SAMBA_VERSION_MAJOR==3
+#if _SAMBA_BUILD_==3
#ifdef malloc
#undef malloc
#endif
@@ -1040,6 +1036,28 @@ static bool test_talloc_ptrtype(void)
return ret;
}
+static bool test_autofree(void)
+{
+#if _SAMBA_BUILD_>=4
+ /*
+ * we can't run this inside smbtorture in samba4
+ * as smbtorture uses talloc_autofree_context()
+ */
+ printf("SKIPPING TALLOC AUTOFREE CONTEXT (not supported from smbtorture)\n");
+#else
+ void *p;
+
+ printf("TESTING TALLOC AUTOFREE CONTEXT\n");
+
+ p = talloc_autofree_context();
+ talloc_free(p);
+
+ p = talloc_autofree_context();
+ talloc_free(p);
+#endif
+ return true;
+}
+
bool torture_local_talloc(struct torture_context *torture)
{
bool ret = true;
@@ -1067,13 +1085,14 @@ bool torture_local_talloc(struct torture_context *torture)
if (ret) {
ret &= test_speed();
}
+ ret &= test_autofree();
return ret;
}
-#if !defined(_SAMBA_BUILD_) || ((SAMBA_VERSION_MAJOR==3)&&(SAMBA_VERSION_MINOR<9))
+#if _SAMBA_BUILD_<4
int main(void)
{
if (!torture_local_talloc(NULL)) {