Skip to content

Commit fb011df

Browse files
MDRC: Improve Resource Cleanup in multiband_drc_free
- Added comprehensive documentation for multiband_drc_free function, detailing its purpose, parameters, and the cleanup process. - Introduced validation to check if component data (`cd`) is not NULL before freeing associated resources. - Ensured all allocated resources are properly freed, and nullified the private module data pointer upon cleanup. - Provided clear log messages indicating the start and successful completion of the free operation. - Included necessary comments to clarify code intent and improve maintainability. Signed-off-by: Shriram Shastry <malladi.sastry@intel.com>
1 parent d7ec648 commit fb011df

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/audio/multiband_drc/multiband_drc.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,15 +396,34 @@ static int multiband_drc_init(struct processing_module *mod)
396396
return ret;
397397
}
398398

399+
/**
400+
* @brief Free resources allocated by Multiband DRC processing component.
401+
*
402+
* This function releases all memory and resources associated with the
403+
* multiband DRC component's operation. This includes dynamically allocated
404+
* filter state instances as well as freeing up the model handler.
405+
*
406+
* @param[in] mod Pointer to the processing module to be freed.
407+
*
408+
* @return 0 indicating success.
409+
*/
399410
static int multiband_drc_free(struct processing_module *mod)
400411
{
401412
struct multiband_drc_comp_data *cd = module_get_private_data(mod);
402413

403414
comp_info(mod->dev, "multiband_drc_free()");
404415

405-
comp_data_blob_handler_free(cd->model_handler);
416+
if (cd) {
417+
/* Freeing other resources as part of the component data */
418+
comp_data_blob_handler_free(cd->model_handler);
419+
420+
/* Free the main component data structure */
421+
rfree(cd);
422+
423+
/* Clear the private module data pointer */
424+
module_set_private_data(mod, NULL);
425+
}
406426

407-
rfree(cd);
408427
return 0;
409428
}
410429

0 commit comments

Comments
 (0)