sensord: lazy loading atexit() because static variables is used in atexit() 64/60864/1
authorkibak.yoon <kibak.yoon@samsung.com>
Wed, 2 Mar 2016 14:38:31 +0000 (23:38 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Wed, 2 Mar 2016 14:38:31 +0000 (23:38 +0900)
- if atexit() is called before the declaration of static variables,
  they can be released while the registered callback is processing.
- so atexit() function has to be called lazily.

Change-Id: I2feef2013d01470559ad51f8712fbd8ea9f2ae02
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
src/client/client.cpp

index 96a3e95..3ab4146 100644 (file)
@@ -56,14 +56,14 @@ public:
        {
                sensor_event_listener::get_instance().set_hup_observer(restore_session);
        }
-
-       ~initiator()
-       {
-               _D("Good bye! %s\n", get_client_name());
-               clean_up();
-       }
 };
 
+void good_bye(void)
+{
+       _I("Good bye! %s\n", get_client_name());
+       clean_up();
+}
+
 static initiator g_initiator;
 
 static int g_power_save_state_cb_cnt = 0;
@@ -540,6 +540,9 @@ API int sensord_connect(sensor_t sensor)
 
        sensor_registered = sensor_client_info::get_instance().is_sensor_registered(sensor_id);
 
+       // lazy loading after creating static variables
+       atexit(good_bye);
+
        handle = sensor_client_info::get_instance().create_handle(sensor_id);
        if (handle == MAX_HANDLE_REACHED) {
                _E("Maximum number of handles reached, sensor: %s in client %s", get_sensor_name(sensor_id), get_client_name());