PATCH: Leak fix for bonobo-property-bag and bonobo-transient



Hello, dudes,

Here is a patch to fix an ugly leak in bonobo-property-bag and
bonobo-transient.  The CORBA_Policy objects were not being destroyed
when we are done with them.  I have tested this with Evolution, and it
seems to work fine.  Please tell me if it is OK to commit.

IMPORTANT:  For this to work, you will need the latest stable ORBit
from CVS.  There was a bug in the destructor for CORBA_Policy;
versions of ORBit older than yesterday will crash horribly.

  Federico


Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/bonobo/ChangeLog,v
retrieving revision 1.798
diff -u -r1.798 ChangeLog
--- ChangeLog	2000/12/08 01:28:03	1.798
+++ ChangeLog	2000/12/09 06:09:01
@@ -1,3 +1,17 @@
+2000-12-08  Federico Mena Quintero  <federico helixcode com>
+
+	* bonobo/bonobo-property-bag.c (bonobo_property_bag_create_poa):
+	Destroy the policies after we are done with them.  
+
+	* bonobo/bonobo-transient.c (bonobo_transient_construct):
+	Likewise.
+
+	YOU REQUIRE THE LATEST STABLE ORBIT FROM CVS FOR THIS TO WORK!
+	THERE WAS A BUG IN ORBIT THAT WILL MAKE THE CODE CRASH IF YOU USE
+	AN OLDER VERSION.
+
+	SHOUT SHOUT SHOUT SCREAM SCREAM SCREAM.
+
 2000-12-08  Michael Meeks  <michael helixcode com>
 
 	* bonobo/bonobo-async.[ch]: s/ASync/Async/
Index: bonobo/bonobo-property-bag.c
===================================================================
RCS file: /cvs/gnome/bonobo/bonobo/bonobo-property-bag.c,v
retrieving revision 1.33
diff -u -r1.33 bonobo-property-bag.c
--- bonobo/bonobo-property-bag.c	2000/12/07 21:23:12	1.33
+++ bonobo/bonobo-property-bag.c	2000/12/09 06:09:01
@@ -182,7 +182,10 @@
 	BonoboPropertyBagServantManager    *sm;
 	CORBA_Environment		   ev;
 	char				  *poa_name;
+	gboolean			   retval;
 
+	retval = FALSE;
+
 	CORBA_exception_init (&ev);
 
 	/*
@@ -238,10 +241,8 @@
 	
 	if (ev._major != CORBA_NO_EXCEPTION) {
 		g_warning ("Could not create request processing policy for BonoboProperty POA");
-		g_free (policies->_buffer);
-		g_free (policies);
 		CORBA_exception_free (&ev);
-		return FALSE;
+		goto out;
 	}
 
 	/*
@@ -272,10 +273,8 @@
 	
 	if (ev._major != CORBA_NO_EXCEPTION) {
 		g_warning ("Could not create servant retention policy for BonoboProperty POA");
-		g_free (policies->_buffer);
-		g_free (policies);
 		CORBA_exception_free (&ev);
-		return FALSE;
+		goto out;
 	}
 
 	/*
@@ -291,11 +290,9 @@
 	
 	if (ev._major != CORBA_NO_EXCEPTION){
 		g_warning ("Could not create threading policy for BonoboProperty POA");
-		g_free (policies->_buffer);
-		g_free (policies);
 		CORBA_exception_free (&ev);
-		return FALSE;
-	}   
+		goto out;
+	}
 
 	/*
 	 * Create the BonoboProperty POA as a child of the root
@@ -309,15 +306,11 @@
 					       policies,
 					       &ev);
 	g_free (poa_name);
-	
-	
-	g_free (policies->_buffer);
-	g_free (policies);
-	
+
 	if (ev._major != CORBA_NO_EXCEPTION) {
 		g_warning ("BonoboPropertyBag: Could not create BonoboPropertyBag POA");
 		CORBA_exception_free (&ev);
-		return FALSE;
+		goto out;
 	}
 	
 	property_poa = pb->priv->poa;
@@ -335,7 +328,7 @@
 		g_warning ("BonoboPropertyBag: Could not initialize ServantLocator");
 		CORBA_exception_free (&ev);
 		g_free (sm);
-		return FALSE;
+		goto out;
 		
 	}
 
@@ -344,10 +337,47 @@
 		g_warning ("BonoboPropertyBag: Could not set POA servant manager");
 		CORBA_exception_free (&ev);
 		g_free (sm);
-		return FALSE;
+		goto out;
+	}
+
+	retval = TRUE;
+
+ out:
+
+	if (policies->_buffer[0] != NULL) {
+		CORBA_Policy_destroy (policies->_buffer[0], &ev);
+
+		if (ev._major != CORBA_NO_EXCEPTION) {
+			g_warning ("bonobo_property_bag_create_poa(): could not destroy the "
+				   "request processing policy");
+			CORBA_exception_free (&ev);
+		}
+	}
+
+	if (policies->_buffer[1] != NULL) {
+		CORBA_Policy_destroy (policies->_buffer[1], &ev);
+
+		if (ev._major != CORBA_NO_EXCEPTION) {
+			g_warning ("bonobo_property_bag_create_poa(): could not destroy the "
+				   "servant retention policy");
+			CORBA_exception_free (&ev);
+		}
 	}
+
+	if (policies->_buffer[2] != NULL) {
+		CORBA_Policy_destroy (policies->_buffer[2], &ev);
+
+		if (ev._major != CORBA_NO_EXCEPTION) {
+			g_warning ("bonobo_property_bag_create_poa(): could not destroy the "
+				   "threading policy");
+			CORBA_exception_free (&ev);
+		}
+	}
+
+	g_free (policies->_buffer);
+	g_free (policies);
 
-	return TRUE;
+	return retval;
 }
 
 
Index: bonobo/bonobo-transient.c
===================================================================
RCS file: /cvs/gnome/bonobo/bonobo/bonobo-transient.c,v
retrieving revision 1.5
diff -u -r1.5 bonobo-transient.c
--- bonobo/bonobo-transient.c	2000/12/06 17:37:13	1.5
+++ bonobo/bonobo-transient.c	2000/12/09 06:09:02
@@ -178,9 +178,12 @@
 {
 	CORBA_PolicyList		*policies;
 	BonoboTransientServantManager   *sm;
-	CORBA_Environment		ev;
+	CORBA_Environment		 ev;
 	char				*poa_name;
+	gboolean			 success;
 
+	success = FALSE;
+
 	transient->priv->new_servant = new_servant;
 	transient->priv->destroy_servant = destroy_servant;
 	transient->priv->callback_data = data;
@@ -245,10 +248,8 @@
 	
 	if (ev._major != CORBA_NO_EXCEPTION) {
 		g_warning ("Could not create request processing policy for BonoboTransient POA");
-		g_free (policies->_buffer);
-		g_free (policies);
 		CORBA_exception_free (&ev);
-		return NULL;
+		goto out;
 	}
 	
 	/*
@@ -279,10 +280,8 @@
 	
 	if (ev._major != CORBA_NO_EXCEPTION) {
 		g_warning ("Could not create servant retention policy for BonoboTransient POA");
-		g_free (policies->_buffer);
-		g_free (policies);
 		CORBA_exception_free (&ev);
-		return NULL;
+		goto out;
 	}
 	
 	/*
@@ -298,11 +297,9 @@
 	
 	if (ev._major != CORBA_NO_EXCEPTION){
 		g_warning ("Could not create threading policy for BonoboTransient POA");
-		g_free (policies->_buffer);
-		g_free (policies);
 		CORBA_exception_free (&ev);
-		return FALSE;
-	}   
+		goto out;
+	}
 
 	/*
 	 * Create the BonoboProperty POA as a child of the root
@@ -312,17 +309,12 @@
 	transient->priv->poa = PortableServer_POA_create_POA (
 		bonobo_poa (), poa_name, bonobo_poa_manager (),
 		policies, &ev);
-	
 	g_free (poa_name);
-	
-	
-	g_free (policies->_buffer);
-	g_free (policies);
-	
+
 	if (ev._major != CORBA_NO_EXCEPTION) {
 		g_warning ("BonoboTransient: Could not create BonoboTransient POA");
 		CORBA_exception_free (&ev);
-		return NULL;
+		goto out;
 	}
 	
 	/*
@@ -338,8 +330,7 @@
 		g_warning ("BonoboTransient: Could not initialize ServantLocator");
 		CORBA_exception_free (&ev);
 		g_free (sm);
-		return NULL;
-		
+		goto out;
 	}
 
 	PortableServer_POA_set_servant_manager (
@@ -350,10 +341,49 @@
 		g_warning ("BonoboTransient: Could not set POA servant manager");
 		CORBA_exception_free (&ev);
 		g_free (sm);
-		return NULL;
+		goto out;
+	}
+
+	success = TRUE;
+
+ out:
+	if (policies->_buffer[0] != NULL) {
+		CORBA_Policy_destroy (policies->_buffer[0], &ev);
+
+		if (ev._major != CORBA_NO_EXCEPTION) {
+			g_warning ("bonobo_transient_construct(): could not destroy the "
+				   "request processing policy");
+			CORBA_exception_free (&ev);
+			success = FALSE;
+		}
 	}
+
+	if (policies->_buffer[1] != NULL) {
+		CORBA_Policy_destroy (policies->_buffer[1], &ev);
 
-	return transient;
+		if (ev._major != CORBA_NO_EXCEPTION) {
+			g_warning ("bonobo_transient_construct(): could not destroy the "
+				   "servant retention policy");
+			CORBA_exception_free (&ev);
+			success = FALSE;
+		}
+	}
+
+	if (policies->_buffer[2] != NULL) {
+		CORBA_Policy_destroy (policies->_buffer[2], &ev);
+
+		if (ev._major != CORBA_NO_EXCEPTION) {
+			g_warning ("bonobo_transient_construct(): could not destroy the "
+				   "threading policy policy");
+			CORBA_exception_free (&ev);
+			success = FALSE;
+		}
+	}
+
+	if (success)
+		return transient;
+	else
+		return NULL;
 }
 
 static void




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]