From c9becb7b7447e24315ee33d1b3a059e000531729 Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Wed, 3 Jul 2024 14:19:02 +0900 Subject: Modify to allocate hal_backend_sensor_funcs before get backend Previously, the memory for hal backend sensor function was allocated from the hal backend. With new hal ABI versioning, it should be allocated from the hal api. Thus, it is modified to allocate every required memories for hal backend functions in this hal api sensor. Change-Id: Ic001081d03866630423db717d35f2558f8c8a0eb Signed-off-by: SangYoun Kwak --- src/hal-api-sensor.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/hal-api-sensor.cpp b/src/hal-api-sensor.cpp index 02a88b5..7357cf7 100644 --- a/src/hal-api-sensor.cpp +++ b/src/hal-api-sensor.cpp @@ -84,18 +84,28 @@ int hal_sensor_get_backend(void) goto FREE_MEMORY; } - hal_sensor_funcs = (hal_backend_sensor_funcs **)malloc(sizeof(hal_backend_sensor_funcs *) * hal_sensor_count); + hal_sensor_funcs = (hal_backend_sensor_funcs **)calloc(hal_sensor_count, sizeof(*hal_sensor_funcs)); if (!hal_sensor_funcs) { _E("Failed to allocate memory."); goto FREE_MEMORY; } + for(i = 0; i < hal_sensor_count; i++) { + hal_sensor_funcs[i] = (hal_backend_sensor_funcs *)calloc(1, sizeof(**hal_sensor_funcs)); + if (!hal_sensor_funcs[i]) { + _E("Failed to allocate memory."); + goto FREE_MEMORY; + } + } + for(i = 0; i < hal_sensor_count; i++) { ret_getbackend = hal_common_get_backend_with_library_name(HAL_MODULE_SENSOR, (void **)&hal_sensor_funcs[i], hal_sensor_names[i]); if (ret_getbackend < 0) { _E("Failed to get backend (%s)", hal_sensor_names[i]); - } else + FREE(hal_sensor_funcs[i]); + } else { loaded_backend++; + } } if (loaded_backend == 0) { @@ -107,6 +117,12 @@ int hal_sensor_get_backend(void) return 0; FREE_MEMORY: + if (hal_sensor_funcs != NULL) { + for (int i = 0; i < hal_sensor_count; ++i) + FREE(hal_sensor_funcs[i]); + FREE(hal_sensor_funcs); + } + for(i = 0; i < hal_sensor_count; i++) FREE(hal_sensor_names[i]); @@ -127,6 +143,7 @@ int hal_sensor_put_backend(void) for (i = 0; i < hal_sensor_count; i++) { if (hal_sensor_funcs[i]) { hal_common_put_backend_with_library_name(HAL_MODULE_SENSOR, (void *)hal_sensor_funcs[i], hal_sensor_names[i]); + FREE(hal_sensor_funcs[i]); } FREE(hal_sensor_names[i]); } -- cgit v1.2.3