summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/hal-api-sensor.cpp21
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]);
}