Skip to content

Tools: Testbench: Fix notification pool memory leak#10741

Merged
kv2019i merged 3 commits intothesofproject:mainfrom
singalsu:mfcc_fix_memory_leaks
May 4, 2026
Merged

Tools: Testbench: Fix notification pool memory leak#10741
kv2019i merged 3 commits intothesofproject:mainfrom
singalsu:mfcc_fix_memory_leaks

Conversation

@singalsu
Copy link
Copy Markdown
Collaborator

@singalsu singalsu commented May 4, 2026

This PR fixes two MFCC testbench run related memory leaks

  • Tools: Testbench: Fix notification pool memory leak
  • Audio: MFCC: Fix memory leak in mfcc_free()

The notification pool fix triggered an issue in Sound Dose that also needed a fix

  • Audio: Sound Dose: Fix use-after-free in sound_dose_free

singalsu added 3 commits May 4, 2026 14:50
This patch replaces the rfree() of cd->msg with ipc_msg_free()
which properly unlinks the message from the IPC message queue
before freeing it. The direct rfree() left a dangling list entry,
causing a use-after-free when tb_free() drains the queue via
ipc_send_queued_msg().

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
In capture direction testbench runs, pipeline_comp_copy() triggers
send_process_data_error_notif_msg() which allocates a notification
from the pool and queues it to the IPC message list via ipc_msg_send().
On Zephyr targets a work handler calls ipc_send_queued_msg() to process
the queue and invoke the free callback. In the testbench no such
handler exists, so queued notifications are never freed.

Add ipc_notification_pool_free() to notification_pool.c to release
all pool items. In tb_free(), drain the IPC message queue by calling
ipc_send_queued_msg() in a loop, then call ipc_notification_pool_free()
to free the pool before releasing IPC resources.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
The mfcc_free_buffers() need to be called before the component
data cd is freed. The pointers to buffers are members of cd.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
@singalsu singalsu force-pushed the mfcc_fix_memory_leaks branch from ff6f3d1 to e4aa893 Compare May 4, 2026 11:55
@singalsu singalsu marked this pull request as ready for review May 4, 2026 12:10
Copilot AI review requested due to automatic review settings May 4, 2026 12:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes teardown-time memory management issues in the testbench and audio modules so IPC notification/message allocations are released safely during pipeline shutdown. It fits into the codebase by tightening lifecycle cleanup paths for IPC-backed notifications and MFCC buffers.

Changes:

  • Drain queued IPC notifications in testbench teardown and add a library-only notification-pool cleanup helper.
  • Fix sound_dose_free() to release IPC messages via ipc_msg_free() instead of manually freeing raw pointers.
  • Reorder mfcc_free() cleanup so MFCC buffers are freed before the component private data is released.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tools/testbench/utils.c Drains queued IPC messages during testbench shutdown and frees notification-pool items.
src/ipc/notification_pool.c Adds library-only cleanup for notification-pool allocations.
src/include/sof/ipc/notification_pool.h Declares the new notification-pool cleanup API for library builds.
src/audio/sound_dose/sound_dose.c Switches Sound Dose IPC message teardown to the common ipc_msg_free() helper.
src/audio/mfcc/mfcc.c Fixes MFCC free ordering so buffer cleanup happens before freeing module data.

@kv2019i kv2019i merged commit 6e5ad83 into thesofproject:main May 4, 2026
44 of 45 checks passed
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.

4 participants