Skip to content

Memory Leak: Neural Network Allocation Not Freed #81

@Amit-Matth

Description

@Amit-Matth

Description
The audiomark benchmark initialization routine allocates memory for the Neural Network (NN) component via th_nn_init but acts as a "fire and forget" allocation, failing to release it during the teardown phase.

I identified this issue while reviewing src/ee_audiomark.c, where I found an explicit TODO comment indicating that the de-initialization was intended but not implemented: // TODO: De-init NN allocs?.

Location

  • Allocation: In ports/arm/th_api.c, the function th_nn_init() allocates memory to ctx.buf.
  • Missing Deallocation: In src/ee_audiomark.c, the ee_audiomark_release() function frees other components (BMF, AEC, ANR, KWS) but skips the Neural Network memory.

Impact
This results in a memory leak every time the benchmark is run. While the OS may reclaim memory after the process terminates, this behavior is problematic for embedded environments or scenarios where the benchmark functions are called repeatedly within a larger application or test harness.

Code Snippets
src/ee_audiomark.c:

void
ee_audiomark_release(void)
{
    th_free(p_bmf_inst, COMPONENT_BMF);
    th_free(p_aec_inst, COMPONENT_AEC);
    th_free(p_anr_inst, COMPONENT_ANR);
    th_free(p_kws_inst, COMPONENT_KWS);
    // TODO: De-init NN allocs?
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions