mirror of
https://github.com/samba-team/samba.git
synced 2025-12-16 00:23:52 +03:00
r15838: Back-port tridge's talloc fixes (r15824, r15828) from Samba4.
Jeremy.
This commit is contained in:
committed by
Gerald (Jerry) Carter
parent
7c375fd540
commit
f6c110ddb8
@@ -139,6 +139,7 @@ void *talloc_autofree_context(void);
|
|||||||
size_t talloc_get_size(const void *ctx);
|
size_t talloc_get_size(const void *ctx);
|
||||||
void *talloc_find_parent_byname(const void *ctx, const char *name);
|
void *talloc_find_parent_byname(const void *ctx, const char *name);
|
||||||
void talloc_show_parents(const void *context, FILE *file);
|
void talloc_show_parents(const void *context, FILE *file);
|
||||||
|
int talloc_is_parent(const void *context, const char *ptr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -540,7 +540,13 @@ int talloc_free(void *ptr)
|
|||||||
tc = talloc_chunk_from_ptr(ptr);
|
tc = talloc_chunk_from_ptr(ptr);
|
||||||
|
|
||||||
if (tc->refs) {
|
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);
|
talloc_reference_destructor(tc->refs);
|
||||||
|
if (is_child) {
|
||||||
|
return talloc_free(ptr);
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -690,7 +696,7 @@ void *talloc_steal(const void *new_ctx, const void *ptr)
|
|||||||
|
|
||||||
new_tc = talloc_chunk_from_ptr(new_ctx);
|
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);
|
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);
|
return TC_PTR_FROM_CHUNK(tc);
|
||||||
}
|
}
|
||||||
while (tc && tc->prev) tc = tc->prev;
|
while (tc && tc->prev) tc = tc->prev;
|
||||||
tc = tc->parent;
|
if (tc) {
|
||||||
|
tc = tc->parent;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -1300,6 +1309,30 @@ void talloc_show_parents(const void *context, FILE *file)
|
|||||||
while (tc) {
|
while (tc) {
|
||||||
fprintf(file, "\t'%s'\n", talloc_get_name(TC_PTR_FROM_CHUNK(tc)));
|
fprintf(file, "\t'%s'\n", talloc_get_name(TC_PTR_FROM_CHUNK(tc)));
|
||||||
while (tc && tc->prev) tc = tc->prev;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user