eeze/sensor: Fix big memleak that happened on every eeze use.
authorStefan Schmidt <stefan@datenfreihafen.org>
Tue, 2 Oct 2012 08:47:54 +0000 (08:47 +0000)
committerStefan Schmidt <stefan@datenfreihafen.org>
Tue, 2 Oct 2012 08:47:54 +0000 (08:47 +0000)
Really free the list with sensor modules when shutting down. No idea how I
dropped that as I found it in one old local version I had. Thanks to Mike
for the notice and valgrind for the tooling.

Also make sure we don't corrupt the list before we can free it.

SVN revision: 77291

legacy/eeze/src/lib/eeze_sensor.c
legacy/eeze/src/modules/eeze_sensor_fake.c
legacy/eeze/src/modules/eeze_sensor_tizen.c

index 7e1f6b2..2b90555 100644 (file)
@@ -41,7 +41,7 @@ EAPI Eeze_Sensor_Obj *
 eeze_sensor_obj_get(Eeze_Sensor_Type sensor_type)
 {
    Eina_List *l;
-   Eeze_Sensor_Obj *obj;
+   Eeze_Sensor_Obj *obj, *sens;
    Eeze_Sensor_Module *module;
 
    module = _highest_priority_module_get();
@@ -52,7 +52,12 @@ eeze_sensor_obj_get(Eeze_Sensor_Type sensor_type)
      {
         if (obj->type == sensor_type)
           {
-             return obj;
+             sens = calloc(1, sizeof(Eeze_Sensor_Obj));
+             if (!sens) return NULL;
+
+             memcpy(sens, obj, sizeof(Eeze_Sensor_Obj));
+
+             return sens;
           }
      }
    return NULL;
index 30ab5cc..a5be287 100644 (file)
@@ -168,7 +168,12 @@ sensor_fake_init(void)
 void
 sensor_fake_shutdown(void)
 {
+   Eeze_Sensor_Obj *sens;
+
    eeze_sensor_module_unregister("fake");
+   EINA_LIST_FREE(esensor_module->sensor_list, sens)
+      free(sens);
+
    free(esensor_module);
    esensor_module = NULL;
 }
index ae74f6f..ffcc263 100644 (file)
@@ -781,9 +781,14 @@ sensor_tizen_init(void)
 void
 sensor_tizen_shutdown(void)
 {
+   Eeze_Sensor_Obj *sens;
+
    sensor_stop(sensor_handle, SENSOR_MOTION_FACEDOWN);
    sensor_stop(sensor_handle, SENSOR_MOTION_DOUBLETAP);
    eeze_sensor_module_unregister("tizen");
+   EINA_LIST_FREE(esensor_module->sensor_list, sens)
+      free(sens);
+
    free(esensor_module);
    esensor_module = NULL;
 }