Skip to content

Commit 1f32181

Browse files
committed
audio: asrc: Fix heap double-free during teardown
Properly track allocation state in the ASRC component lifecycle to prevent double-free of heap memory during module teardown in ZTest environments. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 1e59ce2 commit 1f32181

1 file changed

Lines changed: 26 additions & 11 deletions

File tree

src/audio/asrc/asrc.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -315,15 +315,25 @@ static void asrc_release_buffers(struct processing_module *mod, struct asrc_farr
315315
static int asrc_free(struct processing_module *mod)
316316
{
317317
struct comp_data *cd = module_get_private_data(mod);
318-
struct comp_dev *dev = mod->dev;
319318

320-
comp_dbg(dev, "entry");
319+
comp_dbg(mod->dev, "entry");
320+
321+
if (!cd)
322+
return 0;
321323

322324
mod_free(mod, cd->buf);
323-
asrc_release_buffers(mod, cd->asrc_obj);
324-
asrc_free_polyphase_filter(mod, cd->asrc_obj);
325-
mod_free(mod, cd->asrc_obj);
325+
cd->buf = NULL;
326+
327+
if (cd->asrc_obj) {
328+
asrc_release_buffers(mod, cd->asrc_obj);
329+
asrc_free_polyphase_filter(mod, cd->asrc_obj);
330+
mod_free(mod, cd->asrc_obj);
331+
cd->asrc_obj = NULL;
332+
}
333+
326334
mod_free(mod, cd);
335+
module_set_private_data(mod, NULL);
336+
327337
return 0;
328338
}
329339

@@ -862,12 +872,17 @@ static int asrc_reset(struct processing_module *mod)
862872
asrc_dai_stop_timestamp(cd);
863873

864874
/* Free the allocations those were done in prepare() */
865-
asrc_release_buffers(mod, cd->asrc_obj);
866-
asrc_free_polyphase_filter(mod, cd->asrc_obj);
867-
mod_free(mod, cd->asrc_obj);
868-
mod_free(mod, cd->buf);
869-
cd->asrc_obj = NULL;
870-
cd->buf = NULL;
875+
if (cd->asrc_obj) {
876+
asrc_release_buffers(mod, cd->asrc_obj);
877+
asrc_free_polyphase_filter(mod, cd->asrc_obj);
878+
mod_free(mod, cd->asrc_obj);
879+
cd->asrc_obj = NULL;
880+
}
881+
882+
if (cd->buf) {
883+
mod_free(mod, cd->buf);
884+
cd->buf = NULL;
885+
}
871886

872887
return 0;
873888
}

0 commit comments

Comments
 (0)