svn commit: samba r15838 - in branches/SAMBA_3_0/source: include lib
jra at samba.org
jra at samba.org
Tue May 23 15:57:27 GMT 2006
Author: jra
Date: 2006-05-23 15:57:26 +0000 (Tue, 23 May 2006)
New Revision: 15838
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=15838
Log:
Back-port tridge's talloc fixes (r15824, r15828) from Samba4.
Jeremy.
Modified:
branches/SAMBA_3_0/source/include/talloc.h
branches/SAMBA_3_0/source/lib/talloc.c
Changeset:
Modified: branches/SAMBA_3_0/source/include/talloc.h
===================================================================
--- branches/SAMBA_3_0/source/include/talloc.h 2006-05-23 15:21:55 UTC (rev 15837)
+++ branches/SAMBA_3_0/source/include/talloc.h 2006-05-23 15:57:26 UTC (rev 15838)
@@ -139,6 +139,7 @@
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
Modified: branches/SAMBA_3_0/source/lib/talloc.c
===================================================================
--- branches/SAMBA_3_0/source/lib/talloc.c 2006-05-23 15:21:55 UTC (rev 15837)
+++ branches/SAMBA_3_0/source/lib/talloc.c 2006-05-23 15:57:26 UTC (rev 15838)
@@ -540,7 +540,13 @@
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 @@
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 @@
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 @@
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;
+}
More information about the samba-cvs
mailing list