summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2006-05-23 18:40:07 +0000
committerGerald Carter <jerry@samba.org>2006-05-23 18:40:07 +0000
commit1f25a5c65a10e77eba8643c99424c8910142be8a (patch)
tree8267ee63d0ec94c82c660919260b35c035adb9d0
parent734dc9a180fe4293b722ed184dbcefc1850c3d9b (diff)
downloadsamba-1f25a5c65a10e77eba8643c99424c8910142be8a.tar.gz
r15841: grab talloc fixes (current up to r15838)
-rw-r--r--WHATSNEW.txt2
-rw-r--r--source/include/talloc.h1
-rw-r--r--source/lib/talloc.c39
3 files changed, 39 insertions, 3 deletions
diff --git a/WHATSNEW.txt b/WHATSNEW.txt
index 898007a5a8d..a6ff0bc0628 100644
--- a/WHATSNEW.txt
+++ b/WHATSNEW.txt
@@ -61,6 +61,8 @@ o Jeremy Allison <jra@samba.org>
* Instruct winbindd to ignore fd_set when select() returns -1.
* BUG 3779: Make nmbd udp sockets non-blocking to prevent problem
with select returning true but no data being available.
+ * Backport talloc_steal() fixes from SAMBA_4_0 (original fixes by
+ Andrew Tridgell).
o Timur Bakeyev <timur@com.bat.ru>
diff --git a/source/include/talloc.h b/source/include/talloc.h
index 1001a951702..17032ac7acc 100644
--- a/source/include/talloc.h
+++ b/source/include/talloc.h
@@ -139,6 +139,7 @@ void *talloc_autofree_context(void);
size_t talloc_get_size(const void *ctx);
void *talloc_find_parent_byname(const void *ctx, const char *name);
void talloc_show_parents(const void *context, FILE *file);
+int talloc_is_parent(const void *context, const char *ptr);
#endif
diff --git a/source/lib/talloc.c b/source/lib/talloc.c
index c1116155065..51087ef9791 100644
--- a/source/lib/talloc.c
+++ b/source/lib/talloc.c
@@ -540,7 +540,13 @@ int talloc_free(void *ptr)
tc = talloc_chunk_from_ptr(ptr);
if (tc->refs) {
+ int is_child;
+ struct talloc_reference_handle *handle = tc->refs;
+ is_child = talloc_is_parent(handle, handle->ptr);
talloc_reference_destructor(tc->refs);
+ if (is_child) {
+ return talloc_free(ptr);
+ }
return -1;
}
@@ -690,7 +696,7 @@ void *talloc_steal(const void *new_ctx, const void *ptr)
new_tc = talloc_chunk_from_ptr(new_ctx);
- if (tc == new_tc) {
+ if (tc == new_tc || tc->parent == new_tc) {
return discard_const_p(void, ptr);
}
@@ -1278,7 +1284,10 @@ void *talloc_find_parent_byname(const void *context, const char *name)
return TC_PTR_FROM_CHUNK(tc);
}
while (tc && tc->prev) tc = tc->prev;
- tc = tc->parent;
+ if (tc) {
+ tc = tc->parent;
+ }
+
}
return NULL;
}
@@ -1300,6 +1309,30 @@ void talloc_show_parents(const void *context, FILE *file)
while (tc) {
fprintf(file, "\t'%s'\n", talloc_get_name(TC_PTR_FROM_CHUNK(tc)));
while (tc && tc->prev) tc = tc->prev;
- tc = tc->parent;
+ if (tc) {
+ tc = tc->parent;
+ }
}
}
+
+/*
+ return 1 if ptr is a parent of context
+*/
+int talloc_is_parent(const void *context, const char *ptr)
+{
+ struct talloc_chunk *tc;
+
+ if (context == NULL) {
+ return 0;
+ }
+
+ tc = talloc_chunk_from_ptr(context);
+ while (tc) {
+ if (TC_PTR_FROM_CHUNK(tc) == ptr) return 1;
+ while (tc && tc->prev) tc = tc->prev;
+ if (tc) {
+ tc = tc->parent;
+ }
+ }
+ return 0;
+}