FELIX-2289 Synchronize all access to internal maps to prevent data structure corruption

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@934927 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
index 1116ae8..8c51285 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
@@ -119,7 +119,11 @@
             throw new ComponentException( "Failed activating component" );
         }
 
-        m_componentInstances.put( cm, cm );
+        synchronized ( m_componentInstances )
+        {
+            m_componentInstances.put( cm, cm );
+        }
+
         return instance;
     }
 
@@ -231,9 +235,15 @@
         }
         else if ( m_isConfigurationFactory )
         {
-            if ( m_configuredServices != null )
+            Map configuredServices = m_configuredServices;
+            if ( configuredServices != null )
             {
-                ImmediateComponentManager cm = ( ImmediateComponentManager ) m_configuredServices.remove( pid );
+                ImmediateComponentManager cm;
+                synchronized ( configuredServices )
+                {
+                    cm = ( ImmediateComponentManager ) configuredServices.remove( pid );
+                }
+
                 if ( cm != null )
                 {
                     log( LogService.LOG_DEBUG, "Disposing component after configuration deletion", null );
@@ -259,13 +269,18 @@
         else if ( m_isConfigurationFactory )
         {
             ImmediateComponentManager cm;
-            if ( m_configuredServices != null )
+            Map configuredServices = m_configuredServices;
+            if ( configuredServices != null )
             {
-                cm = ( ImmediateComponentManager ) m_configuredServices.get( pid );
+                synchronized ( configuredServices )
+                {
+                    cm = ( ImmediateComponentManager ) configuredServices.get( pid );
+                }
             }
             else
             {
                 m_configuredServices = new HashMap();
+                configuredServices = m_configuredServices;
                 cm = null;
             }
 
@@ -285,7 +300,10 @@
                 }
 
                 // keep a reference for future updates
-                m_configuredServices.put( pid, cm );
+                synchronized ( configuredServices )
+                {
+                    configuredServices.put( pid, cm );
+                }
 
             }
             else
@@ -336,7 +354,10 @@
             cms[i].dispose( reason );
         }
 
-        m_componentInstances.clear();
+        synchronized ( m_componentInstances )
+        {
+            m_componentInstances.clear();
+        }
 
         cms = getComponentManagers( m_configuredServices );
         for ( int i = 0; i < cms.length; i++ )