Re: ORBit bug?



Hi,

> This indeed is an ORBit bug. And I see no easy way to solve that. Even 
> calling Bonobo_PropertySet__free(&set, NULL, CORBA_FALSE); wouldn't help, as
> ORBit_demarshal_any will be called with dup_strings=TRUE, so we would gain a
> memory hole. (which of course is better than the current state of affairs,
> which simply says, that calling SetValues will result in an dying server). I
> do not know the idl-compiler enough to fix that.
> 
> We had a nice feature in the now dead-declared CVS HEAD, that would do 
> without free_strings by prefixing all nonfreeable strings by a magic 
> constant (the place is always free because it otherwise hosts the string 
> size) Is there any chance that we backport that, Elliot? Or are you going 
> to fix that otherwise?

Following up on my on post: I sat down today and implemented that. It
was rather easy and is a small patch. Electric Fence and memprof on
test/everything showed, that it yields the expected results and the
best thing is, that no changed to the idl-compiler had been necessary
(even though it would have been cleaner with changes to
orbit-idl). That means, that indeed the patched ORBit can be used as a
drop in replacement for older ORBit versions without having to
recompile the idl-files. Even new idl-files can work with old
ORBit-versions. This of course is nice and would allow for the
immediate includion of this patch into ORBit, which would fix the
above mentioned bug.

What do you think, Elliot?

Bye,
Sebastian

-- 
Sebastian Wilhelmi                   |            här ovanför alla molnen
mailto:wilhelmi ira uka de           |     är himmlen så förunderligt blå
http://goethe.ira.uka.de/~wilhelmi   |
Index: src/orb/allocators.c
===================================================================
RCS file: /cvs/gnome/ORBit/src/orb/allocators.c,v
retrieving revision 1.34.4.4
diff -u -b -B -r1.34.4.4 allocators.c
--- src/orb/allocators.c	2001/01/08 21:50:41	1.34.4.4
+++ src/orb/allocators.c	2001/03/10 16:52:18
@@ -11,6 +11,8 @@
 x, ORBIT_ROOT_OBJECT(x)->refs); CORBA_Object_duplicate(x, y); })
 #endif
 
+#define FREE_MARKER_IS_ALLOCATED 0xfffffefe
+
 /* The memory chunk stuff */
 
 #define ALLOCATOR_DEFINITION
@@ -82,6 +84,7 @@
 #endif
 	block->free = freefunc;
 	block->func_data = func_data;
+	block->free_marker= FREE_MARKER_IS_ALLOCATED;
 
 	return MEMINFO_TO_PTR(block);
 }
@@ -101,7 +104,7 @@
  */
 
 void
-ORBit_free(gpointer mem, CORBA_boolean free_strings)
+ORBit_free(gpointer mem, CORBA_boolean ignore)
 {
 	ORBit_mem_info *block;
 
@@ -110,6 +113,12 @@
 
 	block = PTR_TO_MEMINFO(mem);
 
+	/* This block has not been allocated by CORBA_alloc. Instead
+         * it is memory in the receive buffer, that has been used in
+         * demarshalling. Let's just return. */
+	if (block->free_marker != FREE_MARKER_IS_ALLOCATED)
+		return;
+
 #ifdef ORBIT_DEBUG
 	g_assert(block->magic == 0xdeadbeef);
 #endif
@@ -130,7 +139,7 @@
 #endif
 
 		for(i = 0, x = mem; i < (gulong)block->func_data; i++)
-			x = block->free(x, my_data, free_strings);
+			x = block->free(x, my_data, CORBA_TRUE);
 
 		if((gpointer)block->free == (gpointer)ORBit_free_via_TypeCode)
 			/* ((guchar *)block) -= sizeof(CORBA_TypeCode); */
@@ -145,7 +154,7 @@
 /* These aren't currently used... */
 
 gpointer
-ORBit_free_via_TypeCode(gpointer mem, gpointer tcp, gboolean free_strings)
+ORBit_free_via_TypeCode(gpointer mem, gpointer tcp, gboolean ignore)
 {
 	CORBA_TypeCode tc = *(CORBA_TypeCode *)tcp, subtc;
 	int i;
@@ -182,7 +191,7 @@
 		for(i = 0; i < tc->sub_parts; i++) {
 			subtc = (CORBA_TypeCode)CORBA_Object_duplicate((CORBA_Object)tc->subtypes[i], NULL);
 			mem = ORBit_free_via_TypeCode(mem, &subtc,
-						      free_strings);
+						      CORBA_TRUE);
 		}
 		retval = mem;
 		break;
@@ -197,7 +206,7 @@
 		        sz = MAX(sz, ORBit_gather_alloc_info(tc->subtypes[i]));
 		    }
 		    mem = ALIGN_ADDRESS(mem, al);
-		    ORBit_free_via_TypeCode(mem, &subtc, free_strings);
+		    ORBit_free_via_TypeCode(mem, &subtc, CORBA_TRUE);
 		    /* the end of the body (subtc) may not be the
 		     * same as the end of the union */
 		    retval = (guchar *)mem + sz;
@@ -205,7 +214,6 @@
 		break;
 	case CORBA_tk_wstring:
 	case CORBA_tk_string:
-		if(free_strings)
 			CORBA_free(*(char **)mem);
 		retval = (guchar *)mem + sizeof(char *);
 		break;
@@ -222,13 +230,13 @@
 		for(i = 0; i < tc->length; i++) {
 			subtc = (CORBA_TypeCode)CORBA_Object_duplicate((CORBA_Object)tc->subtypes[0], NULL);
 			mem = ORBit_free_via_TypeCode(mem, &subtc,
-						      free_strings);
+						      CORBA_TRUE);
 		}
 		retval = mem;
 		break;
 	case CORBA_tk_alias:
 		subtc = (CORBA_TypeCode)CORBA_Object_duplicate((CORBA_Object)tc->subtypes[0], NULL);
-		retval = ORBit_free_via_TypeCode(mem, &subtc, free_strings);
+		retval = ORBit_free_via_TypeCode(mem, &subtc, CORBA_TRUE);
 		break;
 	default:
 		/* NB. alignment != alloc size */
Index: src/orb/allocators.h
===================================================================
RCS file: /cvs/gnome/ORBit/src/orb/allocators.h,v
retrieving revision 1.14.4.1
diff -u -b -B -r1.14.4.1 allocators.h
--- src/orb/allocators.h	2000/12/16 18:32:05	1.14.4.1
+++ src/orb/allocators.h	2001/03/10 16:52:18
@@ -31,7 +31,7 @@
 
 typedef gpointer (*ORBit_free_childvals)(gpointer mem,
 					 gpointer func_data,
-					 CORBA_boolean free_strings);
+					 CORBA_boolean ignore);
 
 /* Please make sure this structure's size is divisible by 8, at least. */
 typedef struct {
@@ -42,6 +42,16 @@
 	   the memory block itself */
 	ORBit_free_childvals free; /* function pointer to free function */
 	gpointer func_data;
+	/* This free_marker is used to distinguish between memory,
+	 * which has to be freed (in that case free_marker is
+	 * FREE_MARKER_IS_ALLOCATED [0xfffffefe]) or memory, which
+	 * must not be freed as it is a string residing in the receive
+	 * buffer of a request (in that case free_marker per GIOP is
+	 * the length of the following string, thus some number
+	 * guaranteed to be smaller than 0xfffffefe, I don't think, we
+	 * ever support transferring strings with a length of 4GB ;-)
+	 */
+	CORBA_unsigned_long free_marker; 
 } ORBit_mem_info;
 
 gpointer ORBit_alloc(size_t block_size,
@@ -52,11 +62,11 @@
 		       gpointer func_data,
 		       size_t before_size);
 
-void ORBit_free(gpointer mem, CORBA_boolean free_strings);
+void ORBit_free(gpointer mem, CORBA_boolean ignore);
 
 /* internal stuff */
 gpointer ORBit_free_via_TypeCode(gpointer mem,
 				 gpointer tcp,
-				 gboolean free_strings);
+				 gboolean ignore);
 
 #endif /* ALLOCATORS_H */
Index: src/orb/orbit.c
===================================================================
RCS file: /cvs/gnome/ORBit/src/orb/orbit.c,v
retrieving revision 1.60.4.4
diff -u -b -B -r1.60.4.4 orbit.c
--- src/orb/orbit.c	2001/01/18 20:16:44	1.60.4.4
+++ src/orb/orbit.c	2001/03/10 16:52:20
@@ -117,12 +117,12 @@
  * fashion.
  */
 gpointer
-CORBA_any__free(gpointer mem, gpointer func_data, CORBA_boolean free_strings)
+CORBA_any__free(gpointer mem, gpointer func_data, CORBA_boolean ignore)
 {
 	CORBA_any *aval = mem;
 
 	if(aval->_release)
-		ORBit_free(aval->_value, free_strings);
+		ORBit_free(aval->_value, CORBA_TRUE);
 	CORBA_Object_release((CORBA_Object)aval->_type, NULL);
 
 	return aval + 1;
@@ -339,7 +339,7 @@
 /* This is needed by skels, that generate a __free function when they see
    the TypeCode interface */
 gpointer
-CORBA_TypeCode__free(gpointer mem, gpointer func_data, CORBA_boolean free_strings)
+CORBA_TypeCode__free(gpointer mem, gpointer func_data, CORBA_boolean ignore)
 {
 	CORBA_Object_release(*(CORBA_Object *)mem, NULL);
 	return ((guchar *)mem) + sizeof(CORBA_TypeCode);
@@ -364,14 +364,13 @@
 }
 
 gpointer
-CORBA_string__free(gpointer str, gpointer dat, CORBA_boolean free_strings)
+CORBA_string__free(gpointer str, gpointer dat, CORBA_boolean ignore)
 {
-	if(free_strings)
 		CORBA_free(*((gpointer *)str));
 	return (gpointer)((guchar *)str + sizeof(CORBA_char *));
 }
 
-gpointer CORBA_Object__free(gpointer str, gpointer dat, CORBA_boolean free_strings)
+gpointer CORBA_Object__free(gpointer str, gpointer dat, CORBA_boolean ignore)
 {
 	CORBA_Environment ev;
 	CORBA_exception_init(&ev);
Index: src/orb/orbit.h.in
===================================================================
RCS file: /cvs/gnome/ORBit/src/orb/orbit.h.in,v
retrieving revision 1.19.4.3
diff -u -b -B -r1.19.4.3 orbit.h.in
--- src/orb/orbit.h.in	2001/01/15 22:22:40	1.19.4.3
+++ src/orb/orbit.h.in	2001/03/10 16:52:21
@@ -102,9 +102,9 @@
 	void);
 
 extern gpointer CORBA_any__free(gpointer mem, gpointer func_data,
-				CORBA_boolean free_strings);
+				CORBA_boolean ignore);
 extern gpointer CORBA_TypeCode__free(gpointer mem, gpointer func_data,
-				     CORBA_boolean free_strings);
+				     CORBA_boolean ignore);
 
 extern CORBA_boolean ORBit_any_equivalent (CORBA_any *obj,
 					   CORBA_any *any,
@@ -112,9 +112,9 @@
 
 extern CORBA_char *CORBA_string_dup(const CORBA_char *string);
 extern CORBA_char *CORBA_string_alloc(CORBA_unsigned_long len);
-extern gpointer CORBA_string__free(gpointer str, gpointer dat, CORBA_boolean free_strings);
+extern gpointer CORBA_string__free(gpointer str, gpointer dat, CORBA_boolean ignore);
 
-gpointer CORBA_Object__free(gpointer str, gpointer dat, CORBA_boolean free_strings);
+gpointer CORBA_Object__free(gpointer str, gpointer dat, CORBA_boolean ignore);
 
 extern CORBA_wchar *CORBA_wstring_alloc(CORBA_unsigned_long len);
 #define CORBA_wstring_free CORBA_string_free


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