Fixed leaks in ORBit.



Hi,

Today I sat down and used memprof on test/everything/server and found some
memleaks. Here's my report:

There is an unreleased PortableServer_ObjectId in
PortableServer_POA_servant_to_reference. That should be rather obvious, I
hope.

-------------

The function tc_dec in orbit_typecode.c says

(((ORBit_RootObject)tc)->refs=-1; /* negative so that it doesn't get freed by
                                     CORBA_Object_release() */

But it should get freed, so I changed it to

CORBA_Object_duplicate(tc, NULL);

to make the reference count 1. That meant, that I had to remove
CORBA_Object_duplicate from all places calling tc_dec. I do however think,
that a function that creates an object should return with a refcount of 1. But
thats not important, we could as well leave refs at 0 and duplicate it
afterwards. What's the policy here?

As ORBit_decode_CORBA_TypeCode in ORBit_demarshal_any in corba_any.c now
returns an Object with refcount 1 we do not need to increase the refcount
here.

In MEMBER_LOOPER_DEC in orbit_typecode.c I added a cast (to remove a compiler
warning) and instead of g_new we have to use ORBit_alloc, as _value will be
freed by CORBA_free.

-------------

Now for the changes in the idl-compiler:

In cbe_skel_op_param_free the parameter for cbe_skel_param_subfree should be
free_internal instead of FALSE.

In the same function A typecode should also be released after usage.

-------------

The other changes are changes to the 'everything' test to really do the right
thing and properly release all memory. Now I have the 'everything' server here
without a memleak and working. Also all other tests are still working. Of
course I'm not 100% sure, that no program out there will break, but I would
suggest committing these changes.

Any thoughts, Elliot?

Patch is attached.

Bye,
Sebastian


-- 
Sebastian Wilhelmi
mailto:wilhelmi ira uka de
http://goethe.ira.uka.de/~wilhelmi
Index: src/orb/corba_any.c
===================================================================
RCS file: /cvs/gnome/ORBit/src/orb/corba_any.c,v
retrieving revision 1.32.4.2
diff -u -b -B -r1.32.4.2 corba_any.c
--- src/orb/corba_any.c	2001/01/08 21:50:41	1.32.4.2
+++ src/orb/corba_any.c	2001/03/02 15:07:18
@@ -700,7 +700,6 @@
     CORBA_any_set_release(retval, CORBA_TRUE);
 
     ORBit_decode_CORBA_TypeCode(&retval->_type, buf);
-    CORBA_Object_duplicate((CORBA_Object)retval->_type, NULL);
 
     val = retval->_value = ORBit_demarshal_allocate_mem(retval->_type, 1);
     ORBit_demarshal_value(buf, &val, retval->_type, dup_strings, orb);
Index: src/orb/orbit_typecode.c
===================================================================
RCS file: /cvs/gnome/ORBit/src/orb/orbit_typecode.c,v
retrieving revision 1.24.4.2
diff -u -b -B -r1.24.4.2 orbit_typecode.c
--- src/orb/orbit_typecode.c	2001/01/28 22:17:50	1.24.4.2
+++ src/orb/orbit_typecode.c	2001/03/02 15:07:18
@@ -318,9 +318,8 @@
 	ORBit_RootObject_set_interface((ORBit_RootObject)tc,
 				       (ORBit_RootObject_Interface *)&ORBit_TypeCode_epv,
 				       NULL);
-
+	CORBA_Object_duplicate(tc, NULL);
 	tc->kind=kind;
-	((ORBit_RootObject)tc)->refs=-1;   /* negative so that it doesn't get freed by CORBA_Object_release() */
 	switch(info->type){
 		guint tmp_index;
 		CORBA_octet o;
@@ -375,7 +374,6 @@
 	t->subtypes=g_new(CORBA_TypeCode, 1);
 	tc_dec(&t->subtypes[0], c, ctx);
 	t->sub_parts=1;
-	CORBA_Object_duplicate((CORBA_Object)t->subtypes[0], NULL);
 	CDR_get_ulong(c, &t->length);
 }
 
@@ -412,7 +410,6 @@
 	for(i=0;i<t->sub_parts;i++){
 		CDR_get_string(c, (char **)&t->subnames[i]);
 		tc_dec(&t->subtypes[i], c, ctx);
-		CORBA_Object_duplicate((CORBA_Object)t->subtypes[i], NULL);
 	}
 }	
 
@@ -465,7 +462,6 @@
 	CDR_get_string(c, (char **)&t->repo_id);
 	CDR_get_string(c, (char **)&t->name);
 	tc_dec(&t->discriminator, c, ctx);
-	CORBA_Object_duplicate((CORBA_Object)t->discriminator, NULL);
 	CDR_get_ulong(c, &t->default_index);
 	CDR_get_ulong(c, &t->sub_parts);
 
@@ -476,14 +472,13 @@
 #define MEMBER_LOOPER_DEC(getname, typename, tkname) \
     case CORBA_tk_##tkname: \
 	for(i=0;i<t->sub_parts;i++){ 	\
-	    t->sublabels[i]._type = 	\
+	    t->sublabels[i]._type = (CORBA_TypeCode) \
 	      CORBA_Object_duplicate((CORBA_Object)t->discriminator, NULL); \
-	    t->sublabels[i]._value = g_new(CORBA_##typename,1); \
+	    t->sublabels[i]._value = ORBit_alloc(sizeof(CORBA_##typename), NULL, NULL); \
 	    t->sublabels[i]._release = CORBA_TRUE; \
 	    CDR_get_##getname(c, t->sublabels[i]._value); \
 	    CDR_get_string(c, (char **)&t->subnames[i]); \
 	    tc_dec(&t->subtypes[i], c, ctx); \
-	    CORBA_Object_duplicate((CORBA_Object)t->subtypes[i], NULL); \
 	} \
 	break
 
@@ -530,7 +525,6 @@
 	t->subtypes=g_new(CORBA_TypeCode, 1);
 	t->sub_parts=1;
 	tc_dec(t->subtypes, c, ctx);
-	CORBA_Object_duplicate((CORBA_Object)t->subtypes[0], NULL);
 }
 
 
@@ -557,7 +551,6 @@
 	for(i=0;i<t->sub_parts;i++){
 		CDR_get_string(c, (char **)&t->subnames[i]);
 		tc_dec(&t->subtypes[i], c, ctx);
-		CORBA_Object_duplicate((CORBA_Object)t->subtypes[i], NULL);
 	}
 }
 
@@ -571,7 +564,6 @@
 {
 	t->subtypes=g_new(CORBA_TypeCode, 1);
 	tc_dec(t->subtypes, c, ctx);
-	CORBA_Object_duplicate((CORBA_Object)t->subtypes[0], NULL);
 	CDR_get_ulong(c, &t->length);
 	t->sub_parts=1;
 }
Index: src/orb/poa.c
===================================================================
RCS file: /cvs/gnome/ORBit/src/orb/poa.c,v
retrieving revision 1.62.4.2
diff -u -b -B -r1.62.4.2 poa.c
--- src/orb/poa.c	2000/11/09 20:14:07	1.62.4.2
+++ src/orb/poa.c	2001/03/02 15:07:19
@@ -879,6 +879,9 @@
 	}
 	retval = PortableServer_POA_id_to_reference(obj,orig_id,ev);
 
+	if (implicit && activate_able)
+		CORBA_free (orig_id);
+
 	return retval;
 }
 
Index: src/orbit-idl-compiler/backends/c/orbit-idl-c-skels.c
===================================================================
RCS file: /cvs/gnome/ORBit/src/orbit-idl-compiler/backends/c/orbit-idl-c-skels.c,v
retrieving revision 1.9.4.3
diff -u -b -B -r1.9.4.3 orbit-idl-c-skels.c
--- src/orbit-idl-compiler/backends/c/orbit-idl-c-skels.c	2001/01/28 22:17:50	1.9.4.3
+++ src/orbit-idl-compiler/backends/c/orbit-idl-c-skels.c	2001/03/02 15:07:19
@@ -411,11 +411,12 @@
     case IDLN_TYPE_STRUCT:
     case IDLN_TYPE_ARRAY:
     case IDLN_TYPE_ANY:
-      cbe_skel_param_subfree(tree, ci, FALSE);
+      cbe_skel_param_subfree(tree, ci, free_internal);
       break;
     case IDLN_TYPE_OBJECT:
     case IDLN_INTERFACE:
     case IDLN_FORWARD_DCL:
+    case IDLN_TYPE_TYPECODE:
       fprintf(ci->fh, "CORBA_Object_release(%s, ev);\n",
 	      IDL_IDENT(IDL_PARAM_DCL(tree).simple_declarator).str);
       break;
Index: test/everything/anyServer.c
===================================================================
RCS file: /cvs/gnome/ORBit/test/everything/Attic/anyServer.c,v
retrieving revision 1.1.2.3
diff -u -b -B -r1.1.2.3 anyServer.c
--- test/everything/anyServer.c	2001/01/28 22:17:50	1.1.2.3
+++ test/everything/anyServer.c	2001/03/02 15:07:19
@@ -46,6 +46,7 @@
 
   if(CORBA_any_get_release(inoutArg)){
 	CORBA_free(inoutArg->_value);
+	CORBA_Object_release((CORBA_Object)inoutArg->_type, ev);
   }
 
 
@@ -84,6 +85,7 @@
 
   if(CORBA_any_get_release(inoutArg)){
 	CORBA_free(inoutArg->_value);
+	CORBA_Object_release((CORBA_Object)inoutArg->_type, ev);
   }
 
   inoutArg->_type = (CORBA_TypeCode)TC_string;
@@ -125,6 +127,7 @@
 
   if(CORBA_any_get_release(inoutArg)){
 	CORBA_free(inoutArg->_value);
+	CORBA_Object_release((CORBA_Object)inoutArg->_type, ev);
   }
 
   inoutArg->_type = (CORBA_TypeCode)TC_test_VariableLengthStruct;
Index: test/everything/basicServer.c
===================================================================
RCS file: /cvs/gnome/ORBit/test/everything/Attic/basicServer.c,v
retrieving revision 1.1.2.1
diff -u -b -B -r1.1.2.1 basicServer.c
--- test/everything/basicServer.c	2001/01/15 22:22:44	1.1.2.1
+++ test/everything/basicServer.c	2001/03/02 15:07:19
@@ -103,6 +103,7 @@
   ex->aseq._buffer = CORBA_sequence_CORBA_long_allocbuf(1);
   ex->aseq._length = 1;
   ex->aseq._buffer[0] = constants_LONG_IN;
+  CORBA_sequence_set_release(&ex->aseq, CORBA_TRUE);
   ex->factory = getFactoryInstance(ev);
 
   CORBA_exception_set(ev,CORBA_USER_EXCEPTION,ex_test_TestException,ex);
Index: test/everything/sequenceServer.c
===================================================================
RCS file: /cvs/gnome/ORBit/test/everything/Attic/sequenceServer.c,v
retrieving revision 1.1.2.1
diff -u -b -B -r1.1.2.1 sequenceServer.c
--- test/everything/sequenceServer.c	2001/01/15 22:22:44	1.1.2.1
+++ test/everything/sequenceServer.c	2001/03/02 15:07:19
@@ -40,9 +40,11 @@
 	g_assert(strcmp(inoutArg->_buffer[i],constants_SEQ_STRING_INOUT_IN[i]) == 0);
   }
 
+  if (CORBA_sequence_get_release (inoutArg))
   CORBA_free(inoutArg->_buffer);
   inoutArg->_buffer = CORBA_sequence_CORBA_string_allocbuf(2);
   inoutArg->_length = 2;
+  CORBA_sequence_set_release(inoutArg, CORBA_TRUE);
   
   for (i=0;i<inoutArg->_length;i++)
 	inoutArg->_buffer[i] = CORBA_string_dup(constants_SEQ_STRING_INOUT_OUT[i]);
@@ -50,6 +52,7 @@
   *outArg = CORBA_sequence_CORBA_string__alloc();
   (*outArg)->_buffer = CORBA_sequence_CORBA_string_allocbuf(2);
   (*outArg)->_length = 2;
+  CORBA_sequence_set_release(*outArg, CORBA_TRUE);
 
   for (i=0;i<(*outArg)->_length;i++)
 	(*outArg)->_buffer[i] = CORBA_string_dup(constants_SEQ_STRING_OUT[i]);
@@ -58,6 +61,7 @@
   retn = CORBA_sequence_CORBA_string__alloc();
   retn->_buffer = CORBA_sequence_CORBA_string_allocbuf(2);
   retn->_length = 2;
+  CORBA_sequence_set_release(retn, CORBA_TRUE);
 
   for (i=0;i<retn->_length;i++)
 	retn->_buffer[i] = CORBA_string_dup(constants_SEQ_STRING_RETN[i]);
@@ -82,9 +86,11 @@
 	g_assert(strcmp(inoutArg->_buffer[i].a.a,constants_SEQ_STRING_INOUT_IN[i]) == 0);
   }
 
+  if (CORBA_sequence_get_release (inoutArg))
   CORBA_free(inoutArg->_buffer);
   inoutArg->_buffer = CORBA_sequence_test_CompoundStruct_allocbuf(2);
   inoutArg->_length = 2;
+  CORBA_sequence_set_release(inoutArg, CORBA_TRUE);
   
   for (i=0;i<inoutArg->_length;i++)
 	inoutArg->_buffer[i].a.a = CORBA_string_dup(constants_SEQ_STRING_INOUT_OUT[i]);
@@ -92,6 +98,7 @@
   *outArg = CORBA_sequence_test_CompoundStruct__alloc();
   (*outArg)->_buffer = CORBA_sequence_test_CompoundStruct_allocbuf(2);
   (*outArg)->_length = 2;
+  CORBA_sequence_set_release(*outArg, CORBA_TRUE);
 
   for (i=0;i<(*outArg)->_length;i++)
 	(*outArg)->_buffer[i].a.a = CORBA_string_dup(constants_SEQ_STRING_OUT[i]);
@@ -100,6 +107,7 @@
   retn = CORBA_sequence_test_CompoundStruct__alloc();
   retn->_buffer = CORBA_sequence_test_CompoundStruct_allocbuf(2);
   retn->_length = 2;
+  CORBA_sequence_set_release(retn, CORBA_TRUE);
 
   for (i=0;i<retn->_length;i++)
 	retn->_buffer[i].a.a = CORBA_string_dup(constants_SEQ_STRING_RETN[i]);


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