fixed random crash when process subscribes to an object interface 0.11.807
authorKevron Rees <kevron.m.rees@intel.com>
Thu, 13 Mar 2014 17:41:29 +0000 (10:41 -0700)
committerKevron Rees <kevron.m.rees@intel.com>
Thu, 13 Mar 2014 17:41:29 +0000 (10:41 -0700)
ambd/core.cpp
plugins/dbus/automotivemanager.cpp

index ab2d94a..9aebff4 100644 (file)
@@ -61,6 +61,7 @@ Core::~Core()
        for(auto itr = mSinks.begin(); itr != mSinks.end(); ++itr)
        {
                delete *itr;
+               itr = mSinks.begin();
        }
        mSinks.clear();
 }
index c108a2e..bf7b42a 100644 (file)
@@ -329,18 +329,31 @@ static void signalCallback( GDBusConnection *connection,
 {
        AutomotiveManager* manager = static_cast<AutomotiveManager*>(user_data);
 
+       if(!manager)
+       {
+               DebugOut(DebugOut::Error)<<"Bad user_data"<<endl;
+               return;
+       }
+
        gchar* name=nullptr;
        gchar* newOwner=nullptr;
        gchar* oldOwner = nullptr;
        g_variant_get(parameters,"(sss)",&name, &oldOwner, &newOwner);
 
+       std::list<AbstractDBusInterface*> toRemove;
+
        if(std::string(newOwner) == "")
        {
-               for(auto i : manager->subscribedProcesses)
+               for(auto &i : manager->subscribedProcesses)
                {
                        AbstractDBusInterface* iface = i.first;
-                       for(auto n : i.second)
+                       std::list<std::string> theList = i.second;
+
+                       DebugOut()<<"theList.count: "<<theList.size()<<endl;
+
+                       for(auto &n : theList)
                        {
+                               DebugOut()<<"n: "<<n<<endl;
                                if(n == name)
                                {
                                        DebugOut()<<"unreferencing "<<n<<" from the subscription of "<<iface->objectPath()<<endl;
@@ -352,10 +365,16 @@ static void signalCallback( GDBusConnection *connection,
                        if(manager->subscribedProcesses[iface].empty())
                        {
                                DebugOut()<<"No more subscribers.  Unregistering: "<<iface->objectPath()<<endl;
-                               manager->subscribedProcesses.erase(iface);
+                               ///Defer removal to not screw up the list
+                               toRemove.push_back(iface);
                                iface->unregisterObject();
                        }
                }
+
+               for(auto & i : toRemove)
+               {
+                       manager->subscribedProcesses.erase(i);
+               }
        }
 
        g_free(name);