talloc_ref(3)
πΈ talloc_ref(3) β Library Functions Manual πΈ
okay so bestie, this is the talloc_ref page from the Library Functions Manual, and itβs literally all about talloc references. π
πΈ NAME πΈ
talloc_ref β The talloc reference function.
This module contains the definitions around talloc references. β¨
π SYNOPSIS π
π§ Topics π§
The talloc array functions
Talloc contains some handy helpers for handling Arrays conveniently. π
π Functions π
_PUBLIC_ int talloc_increase_ref_count (const void *ptr)β Increase the reference count of a talloc chunk._PUBLIC_ size_t talloc_reference_count (const void *ptr)β Get the number of references to a talloc chunk._PUBLIC_ void * talloc_reference (const void *ctx, const void *ptr)β Create an additional talloc parent to a pointer._PUBLIC_ int talloc_unlink (const void *context, void *ptr)β Remove a specific parent from a talloc chunk._PUBLIC_ void * talloc_autofree_context (void) _DEPRECATED_β Provide a talloc context that is freed at program exit._PUBLIC_ void talloc_show_parents (const void *context, FILE *file)β Show the parentage of a context._PUBLIC_ int talloc_is_parent (const void *context, const void *ptr)β Check if a context is parent of a talloc chunk._PUBLIC_ void * talloc_reparent (const void *old_parent, const void *new_parent, const void *ptr)β Change the parent context of a talloc pointer.
π¦ Detailed Description π¦
This module contains the definitions around talloc references. Thatβs the whole vibe β reference lore lives here. π
π Function Documentation π
π talloc_autofree_context π
_PUBLIC_ void * talloc_autofree_context (void ) _DEPRECATED_
This is the handy utility function that gives you a talloc context that will be automatically freed on program exit. Itβs the move when you want to reduce the noise in memory leak reports. β¨
β οΈ Never use this in code that might be used in objects loaded withdlopenand unloaded withdlclose.talloc_autofree_context()internally usesatexit(3). Some platforms like modern Linux handles this fine, but for example FreeBSD does not deal well withdlopen()andatexit()used simultaneously:dlclose()does not clean up the list of atexit-handlers, so when the program exits the code that was registered from withintalloc_autofree_context()is gone, the program crashes at exit. π
Returns
A talloc context, NULL on error.
π talloc_increase_ref_count π
_PUBLIC_ int talloc_increase_ref_count (const void * ptr)
Increase the reference count of a talloc chunk. The talloc_increase_ref_count(ptr) function is exactly equivalent to:
talloc_reference(NULL, ptr);
You can use either syntax, depending on which you think is clearer in your code. π«Ά
Parameters
ptrβ The pointer to increase the reference count.
Returns
0 on success, -1 on error.
π talloc_is_parent π
_PUBLIC_ int talloc_is_parent (const void * context, const void * ptr)
Check if a context is parent of a talloc chunk. This checks if context is referenced in the talloc hierarchy above ptr. π
Parameters
contextβ The assumed talloc context.ptrβ The talloc chunk to check.
Returns
Return 1 if this is the case, 0 if not.
πΈ talloc_reference πΈ
_PUBLIC_ void * talloc_reference (const void * ctx, const void * ptr)
Create an additional talloc parent to a pointer. The talloc_reference() function makes βcontextβ an additional parent of ptr. Each additional reference consumes around 48 bytes of memory on intel x86 platforms. π
If ptr is NULL, then the function is a no-op, and simply returns NULL.
After creating a reference you can free it in one of the following ways:
- you can
talloc_free()any parent of the original pointer. That will reduce the number of parents of this pointer by1, and will cause this pointer to be freed if it runs out of parents. - you can
talloc_free()the pointer itself if it has at maximum one parent. This behaviour has been changed since the release of version2.0. Further information in the description of"talloc_free".
For more control on which parent to remove, see talloc_unlink(). π§
Parameters
ctxβ The additional parent.ptrβ The pointer you want to create an additional parent for.
Returns
The original pointer 'ptr', NULL if talloc ran out of memory in creating the reference.
β οΈ Warning: You should try to avoid using this interface. It turns a beautiful talloc-tree into a graph. It is often really hard to debug if you screw something up by accident. π
Example:
unsigned int *a, *b, *c;
a = talloc(NULL, unsigned int);
b = talloc(NULL, unsigned int);
c = talloc(a, unsigned int);
// b also serves as a parent of c.
talloc_reference(b, c);
See also
talloc_unlink()
π talloc_reference_count π
_PUBLIC_ size_t talloc_reference_count (const void * ptr)
Get the number of references to a talloc chunk. π₯
Parameters
ptrβ The pointer to retrieve the reference count from.
Returns
The number of references.
π¦ talloc_reparent π¦
_PUBLIC_ void * talloc_reparent (const void * old_parent, const void * new_parent, const void * ptr)
Change the parent context of a talloc pointer. The function changes the parent context of a talloc pointer. It is typically used when the context that the pointer is currently a child of is going to be freed and you wish to keep the memory for a longer time. β¨
The difference between talloc_reparent() and talloc_steal() is that talloc_reparent() can specify which parent you wish to change. This is useful when a pointer has multiple parents via references. π
Parameters
old_parent, new_parent, ptr
Returns
Return the pointer you passed. It does not have any failure modes.
π talloc_show_parents π
_PUBLIC_ void talloc_show_parents (const void * context, FILE * file)
Show the parentage of a context. π
Parameters
contextβ The talloc context to look at.fileβ The output to use, a file,stdoutorstderr.
π talloc_unlink π
_PUBLIC_ int talloc_unlink (const void * context, void * ptr)
Remove a specific parent from a talloc chunk. The function removes a specific parent from ptr. The context passed must either be a context used in talloc_reference() with this pointer, or must be a direct parent of ptr. π«Ά
You can just use talloc_free() instead of talloc_unlink() if there is at maximum one parent. This behaviour has been changed since the release of version 2.0. Further information in the description of "talloc_free".
Parameters
contextβ The talloc parent to remove.ptrβ The talloc ptr you want to remove the parent from.
Returns
0 on success, -1 on error.
π Note: If the parent has already been removed usingtalloc_free()then this function will fail and will return-1. Likewise, ifptrisNULL, then the function will make no modifications and return-1.
β οΈ Warning: You should try to avoid using this interface. It turns a beautiful talloc-tree into a graph. It is often really hard to debug if you screw something up by accident. π
Example:
unsigned int *a, *b, *c;
a = talloc(NULL, unsigned int);
b = talloc(NULL, unsigned int);
c = talloc(a, unsigned int);
// b also serves as a parent of c.
talloc_reference(b, c);
talloc_unlink(b, c);
π Author π
Generated automatically by Doxygen for talloc from the source code. π§
π Sign-off, bestie: this page comes from the talloc source, Version 2.0, and the footerβs date/stamp slot is talloc_ref(3) (no separate date is shown on the page). Mwah! π
π¦ where this page comes from
- centos-stream 10: libtalloc-devel 2.4.4-100.el10 Β· LGPL-3.0-or-later
- fedora 43: libtalloc-devel 2.4.3-4.fc43 Β· LGPL-3.0-or-later
- fedora 43: libtalloc-devel 2.4.3-4.fc43 Β· LGPL-3.0-or-later
- opensuse-leap 16.0: talloc-man 2.4.3-160000.2.2 Β· LGPL-3.0-or-later
- opensuse-leap 16.0: talloc-man 2.4.3-160000.2.2 Β· LGPL-3.0-or-later
- opensuse-leap 16.0: talloc-man 2.4.3-160000.2.2 Β· LGPL-3.0-or-later
- opensuse-leap 16.0: talloc-man 2.4.3-160000.2.2 Β· LGPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms