1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-26 10:04:02 +03:00

r15838: Back-port tridge's talloc fixes (r15824, r15828) from Samba4.

Jeremy.
(This used to be commit f6c110ddb8cfaa1a57dea52818e7611134c2dcfe)
This commit is contained in:
Jeremy Allison 2006-05-23 15:57:26 +00:00 committed by Gerald (Jerry) Carter
parent ec3021dc3b
commit 07c8c98cad
2 changed files with 37 additions and 3 deletions

View File

@ -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

View File

@ -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;
}