Skip to content

Fix: hal_iface_init() is not using malloc() anymore when ATCA_NO_HEAP… - #423

Open
fr89k wants to merge 1 commit into
MicrochipTech:mainfrom
fr89k:bugfix/hal_iface_init_hal_custom_no_heap
Open

Fix: hal_iface_init() is not using malloc() anymore when ATCA_NO_HEAP…#423
fr89k wants to merge 1 commit into
MicrochipTech:mainfrom
fr89k:bugfix/hal_iface_init_hal_custom_no_heap

Conversation

@fr89k

@fr89k fr89k commented Aug 4, 2026

Copy link
Copy Markdown

ATCA_NO_HEAP does not cover the custom-HAL allocation in hal_iface_init()

Affected versions

  • v3.8.0 (d49c7d5)

Configuration

Bare-metal target (no heap), built with:

-DATCA_NO_HEAP=ON -DATCA_HAL_CUSTOM=ON

Problem

With ATCA_NO_HEAP defined, the library is documented (and annotated) to perform no
dynamic memory allocation. However, hal_iface_init() (lib/hal/atca_hal.c) allocates the custom-HAL
function-pointer struct unconditionally when ATCA_CUSTOM_IFACE is used
(lib/hal/atca_hal.c:306-308, v3.8.0):

#ifdef ATCA_HAL_CUSTOM
        if (ATCA_CUSTOM_IFACE == cfg->iface_type)
        {
            *hal = hal_malloc(sizeof(ATCAHAL_t));   /* not gated by ATCA_NO_HEAP */

Observed behaviour

On a heapless target (malloc returns NULL), atcab_init() with a
custom-HAL ATCAIfaceCfg fails with ATCA_ALLOC_FAILURE.

Expected behaviour

With ATCA_NO_HEAP defined, no code path calls hal_malloc/hal_free.

Suggested fix

When using ATCA_NO_HEAP, use a static ATCAHAL_t instance in hal_iface_init() .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant