Merge "Fix memory corruption issue when unregistering surfaces" into flounder flounder 6.0.5 flounder/6.0.5 flounder_6.0.5
authorJan-Simon Moeller <jsmoeller@linuxfoundation.org>
Mon, 18 Feb 2019 10:39:34 +0000 (10:39 +0000)
committerGerrit Code Review <gerrit@automotivelinux.org>
Mon, 18 Feb 2019 10:39:34 +0000 (10:39 +0000)
1  2 
src/runxdg.cpp

diff --combined src/runxdg.cpp
@@@ -28,6 -28,7 +28,7 @@@
  #include <sys/time.h>
  #include <sys/wait.h>
  
+ #include <algorithm>
  #include <cstdio>
  
  #include "cpptoml/cpptoml.h"
@@@ -83,8 -84,7 +84,8 @@@ void RunXDG::notify_ivi_control_cb (ilm
      m_launcher->register_surfpid(surf_pid);
      if (m_launcher->m_rid &&
          surf_pid == m_launcher->find_surfpid_by_rid(m_launcher->m_rid)) {
 -      setup_surface(id);
 +      m_ivi_id = id;
 +      setup_surface();
      }
      m_surfaces[surf_pid] = id;
    } else if (object == ILM_LAYER) {
@@@ -280,16 -280,12 +281,16 @@@ int RunXDG::init_wm (void
      return -1;
    }
  
 -  std::function< void(json_object*) > h_active = [](json_object* object) {
 +  std::function< void(json_object*) > h_active = [this](json_object* object) {
      AGL_DEBUG("Got Event_Active");
 +    t_ilm_surface s_ids[1] = { this->m_ivi_id };
 +    ilm_setInputFocus(s_ids, 1, ILM_INPUT_DEVICE_KEYBOARD, ILM_TRUE);
    };
  
 -  std::function< void(json_object*) > h_inactive = [](json_object* object) {
 +  std::function< void(json_object*) > h_inactive = [this](json_object* object) {
      AGL_DEBUG("Got Event_Inactive");
 +    t_ilm_surface s_ids[1] = { this->m_ivi_id };
 +    ilm_setInputFocus(s_ids, 1, ILM_INPUT_DEVICE_KEYBOARD, ILM_FALSE);
    };
  
    std::function< void(json_object*) > h_visible = [](json_object* object) {
@@@ -476,9 -472,9 +477,9 @@@ RunXDG::RunXDG (int port, const char* t
    AGL_DEBUG("RunXDG created.");
  }
  
 -void RunXDG::setup_surface (int id)
 +void RunXDG::setup_surface (void)
  {
 -  std::string sid = std::to_string(id);
 +  std::string sid = std::to_string(m_ivi_id);
  
    // This surface is mine, register pair app_name and ivi id.
    json_object *obj = json_object_new_object();
@@@ -518,14 -514,10 +519,10 @@@ void POSIXLauncher::register_surfpid (p
  
  void POSIXLauncher::unregister_surfpid (pid_t surf_pid)
  {
-   auto itr = m_pid_v.begin();
-   while (itr != m_pid_v.end()) {
-     if (*itr == surf_pid) {
-       m_pid_v.erase(itr++);
-     } else {
-       ++itr;
-     }
-   }
+   auto beg = m_pid_v.begin();
+   auto end = m_pid_v.end();
+   m_pid_v.erase(std::remove(beg, end, surf_pid), end);
+   AGL_DEBUG("Unregistered surface (id=%d sz=%u)", surf_pid, m_pid_v.size());
  }
  
  pid_t POSIXLauncher::find_surfpid_by_rid (pid_t rid)
@@@ -593,8 -585,6 +590,8 @@@ void RunXDG::start (void
    AGL_DEBUG("waiting for notification: surafce created");
    m_pending_create = true;
  
 +  ilm_commitChanges();
 +
    // in case, target app has already run
    if (m_launcher->m_rid) {
      pid_t surf_pid = m_launcher->find_surfpid_by_rid(m_launcher->m_rid);
          int id = itr->second;
          AGL_DEBUG("surface %d for <%s> already exists", id,
                    m_role.c_str());
 -        setup_surface(id);
 +        m_ivi_id = id;
 +        setup_surface();
        }
      }
    }
 +
 +  ilm_commitChanges();
    m_launcher->loop(e_flag);
  }