From 37306fe3c095529911dd11aba8566619049fc552 Mon Sep 17 00:00:00 2001 From: Shriram Shastry Date: Mon, 19 Aug 2024 00:05:27 +0530 Subject: [PATCH] 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 --- src/audio/multiband_drc/multiband_drc.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/audio/multiband_drc/multiband_drc.c b/src/audio/multiband_drc/multiband_drc.c index a5f064a86e65..e375ce032c37 100644 --- a/src/audio/multiband_drc/multiband_drc.c +++ b/src/audio/multiband_drc/multiband_drc.c @@ -351,15 +351,34 @@ static int multiband_drc_init(struct processing_module *mod) return ret; } +/** + * @brief Free resources allocated by Multiband DRC processing component. + * + * This function releases all memory and resources associated with the + * multiband DRC component's operation. This includes dynamically allocated + * filter state instances as well as freeing up the model handler. + * + * @param[in] mod Pointer to the processing module to be freed. + * + * @return 0 indicating success. + */ static int multiband_drc_free(struct processing_module *mod) { struct multiband_drc_comp_data *cd = module_get_private_data(mod); comp_info(mod->dev, "multiband_drc_free()"); - comp_data_blob_handler_free(cd->model_handler); + if (cd) { + /* Freeing other resources as part of the component data */ + comp_data_blob_handler_free(cd->model_handler); + + /* Free the main component data structure */ + rfree(cd); + + /* Clear the private module data pointer */ + module_set_private_data(mod, NULL); + } - rfree(cd); return 0; }