From 672dffa735835a38540fe397675f47c9819e1388 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 2 Mar 2016 23:38:31 +0900 Subject: [PATCH] sensord: lazy loading atexit() because static variables is used in atexit() - 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 --- src/client/client.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 96a3e95..3ab4146 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -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()); -- 2.7.4