TPM\_Malloc(3) TPM\_Malloc(3)

# [NAME](#NAME)

TPM\_Malloc - Allocate memory

TPM\_Realloc - Reallocate memory

TPM\_Free - Free memory

# [SYNOPSIS](#SYNOPSIS)

**#include &lt;libtpms/tpm\_types.h**&gt;

**#include &lt;libtpms/tpm\_memory.h**&gt;

**#include &lt;libtpms/tpm\_error.h**&gt;

**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](#DESCRIPTION)

The **TPM\_Malloc()** function is used to allocate a buffer of the given size. The allocated buffer will be returned in the *buffer* parameter.

The **TPM\_Realloc()** function is used to resize a buffer. The new size of the buffer is given in the *size* parameter. The reallocated buffer will contain the data from the original buffer.

Both functions have the restriction that the buffer they can allocate is limited to **TPM\_ALLOC\_MAX** (64k) bytes. This size is sufficient for all buffers needed by the TPM.

Upon successful completion, the functions return **TPM\_SUCCESS**. In case the requested buffer exceeds the limit, **TPM\_SIZE** will be returned. See further possible error codes below.

The **TPM\_Free()** function frees the memory previously allocated using either **TPM\_Malloc()** or **TPM\_Realloc()**.

# [ERRORS](#ERRORS)

[**TPM\_SUCCESS**](#TPM_SUCCESS)

The function completed successfully.

[**TPM\_SIZE**](#TPM_SIZE)

The size of the requested buffer exceeds the limit or the system is out of memory.

[**TPM\_FAIL**](#TPM_FAIL)

Requested buffer is of size 0.

For a complete list of TPM error codes please consult the include file **libtpms/tpm\_error.h**

# [SEE ALSO](#SEE_ALSO)

[**TPMLIB\_MainInit**(3)](/man/enterprise-packages/libtpms/TPMLIB_MainInit.3), [**TPMLIB\_Terminate**(3)](/man/enterprise-packages/libtpms/TPMLIB_Terminate.3) [**TPMLIB\_Process**(3)](/man/enterprise-packages/libtpms/TPMLIB_Process.3), [**TPMLIB\_RegisterCallbacks**(3)](/man/enterprise-packages/libtpms/TPMLIB_RegisterCallbacks.3), [**TPMLIB\_GetVersion**(3)](/man/enterprise-packages/libtpms/TPMLIB_GetVersion.3)

2026-10-01 libtpms

---

Document: TPM_Malloc(3) from libtpms 0.10.2-r3 (Chainguard OS)
Source: https://github.com/stefanberger/libtpms
