TPM_Malloc(3)
π TPM_Malloc(3) β the memory one, bestie π
okay so this is a page from libtpms, and it's actually three functions in a trench coat: TPM_Malloc, TPM_Realloc, and TPM_Free. yes they're all on one page, they're a package deal, a friend group. π«Ά
β¨ NAME β¨
TPM_Mallocβ allocate memory, bestie πTPM_Reallocβ reallocate memory (same energy, different size) πTPM_Freeβ free memory, the cleanup icon π
πΈ SYNOPSIS πΈ
like, here's the whole cast, no cap:
#include <libtpms/tpm_types.h>
#include <libtpms/tpm_memory.h>
#include <libtpms/tpm_error.h>
TPM_RESULT TPM_Malloc(unsigned char **buffer,
uint32_t size);
TPM_RESULT TPM_Realloc(unsigned char **buffer,
uint32_t size);
void TPM_Free(unsigned char *buffer);
π¦ DESCRIPTION π¦
so TPM_Malloc() is literally the allocator. you give it a size, it goes and gets you a buffer of exactly that size. the buffer it hands back? it lands in your buffer parameter. main character behavior tbh β¨
TPM_Realloc() is the glow-up function β it resizes a buffer. the new size is whatever you put in size. and the slay part: the reallocated buffer still contains the data from the original buffer. nothing lost, we keep the lore. π
β οΈ okay important vibe check, both of these have a restriction: the biggest buffer they can allocate is TPM_ALLOC_MAX, which is 64k bytes. and ngl, that's plenty β this size is sufficient for all buffers needed by the TPM. so don't come for it. π
upon successful completion, both functions return TPM_SUCCESS. but if the buffer you asked for blows past the limit, you get TPM_SIZE back instead. (and there are more possible error codes right below, keep reading π)
then TPM_Free() is the one who cleans up after the party β it frees memory that was previously allocated using either TPM_Malloc() or TPM_Realloc(). don't mix it up, that's the whole rule. π
π ERRORS π
TPM_SUCCESSβ it worked! we love a successful completion, periodt. πTPM_SIZEβ the requested buffer's size exceeds the limit, or the system is out of memory. two very different problems, same code, iykyk. πTPM_FAILβ the requested buffer is of size0. zero. nothing. it's giving "asked for a buffer the size of my motivation on a monday". π
for a complete list of TPM error codes, please consult the include file libtpms/tpm_error.h β it's got the full receipts, fr fr. π
π SEE ALSO π
the rest of the friend group, go say hi:
TPMLIB_MainInit(3)TPMLIB_Terminate(3)TPMLIB_Process(3)TPMLIB_RegisterCallbacks(3)TPMLIB_GetVersion(3)
okay that's the whole page, you ate that bestie π
β¨ this was libtpms, from 2026-01-02, and the page itself is TPM_Malloc(3) β now go free your buffers, icon. π§π
π¦ where this page comes from
- alpine 3.24: libtpms-doc 0.10.2-r0 Β· BSD-3-Clause
- arch rolling: libtpms 0.10.2-1 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms