[Application] Add removing event_handler in destructor. 88/176088/3
authorLukasz Bardeli <l.bardeli@samsung.com>
Tue, 17 Apr 2018 08:45:24 +0000 (10:45 +0200)
committerLukasz Bardeli <l.bardeli@samsung.com>
Tue, 17 Apr 2018 08:45:24 +0000 (10:45 +0200)
Removing all event_handler from events while closing application.
Without removing event_handler it is possible that native api will call
event with destroyed data. This fix is to prevent such situation

[Verification] Code compiles without error. TCT passrate 100%

Change-Id: I94d1fbb85ad47ca6dbcba6c56cd043521952860e
Signed-off-by: Lukasz Bardeli <l.bardeli@samsung.com>
src/application/application_manager.cc

index 821f0fd98e4e90d7a49f195f1661a938fa0c0cc9..5ac925eedfa349f4faee27cd8870d24d4bd398a9 100644 (file)
@@ -103,6 +103,13 @@ ApplicationManager::ApplicationManager(ApplicationInstance& instance)
 ApplicationManager::~ApplicationManager() {
   ScopeLogger();
   StopAppInfoEventListener();
+  for (auto it = event_handler_map_.begin(); it != event_handler_map_.end();) {
+    int ret = event_remove_event_handler(it->second);
+    if (EVENT_ERROR_NONE != ret) {
+      LoggerE("event_remove_event_handler failed, error: %d (%s)", ret, get_error_message(ret));
+    }
+    it = event_handler_map_.erase(it);
+  }
 }
 
 void ApplicationManager::GetCurrentApplication(const std::string& app_id, picojson::object* out) {