diff options
author | SangYoun Kwak <sy.kwak@samsung.com> | 2024-07-03 14:19:02 +0900 |
---|---|---|
committer | SangYoun Kwak <sy.kwak@samsung.com> | 2024-07-03 16:27:35 +0900 |
commit | c9becb7b7447e24315ee33d1b3a059e000531729 (patch) | |
tree | 4d33124db1da6e38a7efee1856396c58e30a6a71 | |
parent | 058eb06604c9e0bdf08e552fd0782a404b225212 (diff) | |
download | sensor-accepted/tizen_unified_toolchain.tar.gz sensor-accepted/tizen_unified_toolchain.tar.bz2 sensor-accepted/tizen_unified_toolchain.zip |
Modify to allocate hal_backend_sensor_funcs before get backendtizen_9.0_m2_releaseaccepted/tizen/unified/x/asan/20240813.225515accepted/tizen/unified/x/20240705.012348accepted/tizen/unified/toolchain/20240812.131232accepted/tizen/unified/dev/20240708.001556accepted/tizen/unified/20240704.075643accepted/tizen/9.0/unified/20241030.233910tizen_9.0accepted/tizen_unified_x_asanaccepted/tizen_unified_xaccepted/tizen_unified_toolchainaccepted/tizen_unified_devaccepted/tizen_unifiedaccepted/tizen_9.0_unified
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 <sy.kwak@samsung.com>
-rw-r--r-- | src/hal-api-sensor.cpp | 21 |
1 files 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]); } |