Fix the issue Felix-621.
When the instance creation failed, the instance is deleted. This allows deleting both the instance and attached handlers.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@673686 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
index f68e1a9..eda3e82 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
@@ -141,12 +141,23 @@
      */
     public ComponentInstance createInstance(Dictionary config, IPojoContext context, HandlerManager[] handlers) throws org.apache.felix.ipojo.ConfigurationException {
         InstanceManager instance = new InstanceManager(this, context, handlers);
-        instance.configure(m_componentMetadata, config);
+        
         try {
+        	instance.configure(m_componentMetadata, config);
             instance.start();
             return instance;
-        } catch (IllegalStateException e) {
-            // An exception occurs during the start method.
+        } catch (ConfigurationException e) {
+            // An exception occurs while executing the configure or start methods.
+        	if (instance != null) {
+        		instance.dispose();
+        		instance = null;
+        	}
+        	throw e;
+        } catch (Throwable e) { // All others exception are handled here.
+        	if (instance != null) {
+        		instance.dispose();
+        		instance = null;
+        	}
             m_logger.log(Logger.ERROR, e.getMessage(), e);
             throw new ConfigurationException(e.getMessage());
         }