3 #include <ccan/talloc/talloc.h>
6 * talloc_linked - set up an object with an initial link.
7 * @ctx - the context to initially link to
8 * @newobj - the newly allocated object (with a NULL parent)
10 * The object will be freed when @ctx is freed (or talloc_delink(ctx,
11 * newobj) is called), unless more links are added using
14 * For convenient chaining, it returns @newobj on success, or frees
15 * @newobj and returns NULL.
17 #define talloc_linked(ctx, newobj) \
18 ((_TALLOC_TYPEOF(newobj))_talloc_linked((ctx), (newobj)))
21 * talloc_link - add another link to a linkable object.
22 * @ctx - the context to link to
23 * @obj - the object previously made linkable with talloc_linked().
25 * The @obj will only be freed when all contexts linked to it are
26 * freed (or talloc_delink()ed).
28 * Returns @obj, or NULL on failure (out of memory).
30 #define talloc_link(ctx, obj) \
31 ((_TALLOC_TYPEOF(obj))_talloc_link((ctx), (obj)))
34 * talloc_delink - explicitly remove a link from a linkable object.
35 * @ctx - the context previously used for talloc_link/talloc_linked
36 * @obj - the object previously used for talloc_link/talloc_linked
38 * Explicitly remove a link: normally it is implied by freeing @ctx.
39 * Removing the last link frees the object.
41 void talloc_delink(const void *ctx, const void *linked);
43 /* Internal helpers. */
44 void *_talloc_link(const void *ctx, const void *linked);
45 void *_talloc_linked(const void *ctx, const void *linked);
47 #endif /* TALLOC_LINK_H */