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 size 0. 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:


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