1 /* Licensed under GPLv2+ - see LICENSE file for details */
4 #include <ccan/talloc/talloc.h>
7 * talloc_linked - set up an object with an initial link.
8 * @ctx - the context to initially link to
9 * @newobj - the newly allocated object (with a NULL parent)
11 * The object will be freed when @ctx is freed (or talloc_delink(ctx,
12 * newobj) is called), unless more links are added using
15 * For convenient chaining, it returns @newobj on success, or frees
16 * @newobj and returns NULL.
18 #define talloc_linked(ctx, newobj) \
19 ((_TALLOC_TYPEOF(newobj))_talloc_linked((ctx), (newobj)))
22 * talloc_link - add another link to a linkable object.
23 * @ctx - the context to link to
24 * @obj - the object previously made linkable with talloc_linked().
26 * The @obj will only be freed when all contexts linked to it are
27 * freed (or talloc_delink()ed).
29 * Returns @obj, or NULL on failure (out of memory).
31 #define talloc_link(ctx, obj) \
32 ((_TALLOC_TYPEOF(obj))_talloc_link((ctx), (obj)))
35 * talloc_delink - explicitly remove a link from a linkable object.
36 * @ctx - the context previously used for talloc_link/talloc_linked
37 * @obj - the object previously used for talloc_link/talloc_linked
39 * Explicitly remove a link: normally it is implied by freeing @ctx.
40 * Removing the last link frees the object.
42 void talloc_delink(const void *ctx, const void *linked);
44 /* Internal helpers. */
45 void *_talloc_link(const void *ctx, const void *linked);
46 void *_talloc_linked(const void *ctx, const void *linked);
48 #endif /* TALLOC_LINK_H */