---
name: "TPM_Malloc"
section: "3"
platform: "linux"
package: "libtpms"
version: "0.10.2-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/TPM_Malloc"
---

# TPM\_Malloc(3)

Allocate memory TPM\_Realloc - Reallocate memory TPM\_Free - Free memory

## NAME

TPM\_Malloc    - Allocate memory

TPM\_Realloc   - Reallocate memory

TPM\_Free      - Free memory

## SYNOPSIS

**#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

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

- **TPM\_SUCCESS**

  The function completed successfully.

- **TPM\_SIZE**

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

- **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

[**TPMLIB\_MainInit**(3)](/TPMLIB_MainInit/3.md), [**TPMLIB\_Terminate**(3)](/TPMLIB_Terminate/3.md) [**TPMLIB\_Process**(3)](/TPMLIB_Process/3.md), [**TPMLIB\_RegisterCallbacks**(3)](/TPMLIB_RegisterCallbacks/3.md), [**TPMLIB\_GetVersion**(3)](/TPMLIB_GetVersion/3.md)
