Fix crash when more than two wakeup engine exists
authorJi-hoon Lee <dalton.lee@samsung.com>
Fri, 12 Apr 2019 09:49:17 +0000 (18:49 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Mon, 15 Apr 2019 06:54:56 +0000 (15:54 +0900)
For providing a closure to the callback function,
necessary data were stored in a vector and passed
pointer to the data inside the vector, but since
vectors re-arranges internal elements to a new
location when the size gets bigger than its capicity,
pointers to the internal elements get invalidated
which caused crash. For this reason, changed to use
deque instead of vector since deque is a stable
container that preserves internal elements' memory
location.

Change-Id: I2ba578e98d96171aea068b95ea27807b7a143c50

plugins/wakeup-manager/src/wakeup_engine_manager.cpp

index eb8dacb..d236882 100644 (file)
@@ -4,6 +4,7 @@
 #include <dlfcn.h>
 #include <algorithm>
 #include <pkgmgr-info.h>
+#include <deque>
 
 namespace multiassistant
 {
@@ -389,7 +390,6 @@ bool CWakeupEngineManager::on_audio_data_require_status(string engine_name, bool
 
 void CWakeupEngineManager::add_engine(string name, string path)
 {
-       sleep(10);
        MWR_LOGD("Name (%s), Filepath(%s)", name.c_str(), path.c_str());
 
        char* error = NULL;
@@ -477,7 +477,7 @@ void CWakeupEngineManager::add_engine(string name, string path)
                string engine_name;
        } CallbackUserData;
 
-       static vector<CallbackUserData> callback_user_data;
+       static deque<CallbackUserData> callback_user_data;
 
        CallbackUserData user_data;
        user_data.manager = this;
@@ -487,20 +487,20 @@ void CWakeupEngineManager::add_engine(string name, string path)
        if (info.interface.set_wakeup_event_callback) {
                info.interface.set_wakeup_event_callback(
                        [](wakeup_event_info info, void* user_data) {
-                               CallbackUserData *callback_user_data = static_cast<CallbackUserData*>(user_data);
-                               if (nullptr == callback_user_data) return;
-                               if (nullptr == callback_user_data->manager) return;
-                               callback_user_data->manager->on_wakeup_event(callback_user_data->engine_name, info);
+                               CallbackUserData *data = static_cast<CallbackUserData*>(user_data);
+                               if (nullptr == data) return;
+                               if (nullptr == data->manager) return;
+                               data->manager->on_wakeup_event(data->engine_name, info);
                        }, &(callback_user_data.back()));
        }
 
        if (info.interface.set_audio_data_require_status_callback) {
                info.interface.set_audio_data_require_status_callback(
                        [](bool require, void* user_data) {
-                               CallbackUserData *callback_user_data = static_cast<CallbackUserData*>(user_data);
-                               if (nullptr == callback_user_data) return;
-                               if (nullptr == callback_user_data->manager) return;
-                               callback_user_data->manager->on_audio_data_require_status(callback_user_data->engine_name, require);
+                               CallbackUserData *data = static_cast<CallbackUserData*>(user_data);
+                               if (nullptr == data) return;
+                               if (nullptr == data->manager) return;
+                               data->manager->on_audio_data_require_status(data->engine_name, require);
                        }, &(callback_user_data.back()));
        }