ORBit_sequence fixes



Hello

I would like to commit this patch. It fixes memory leak problem in 
ORBit_sequence_alloc and also setting of initial length. In addition 
length calculation in ORBit_sequence_append can handle 0 zero capacity 
sequence now.  The test in test/everything/client.c for ORbit_sequence* 
familiy has been extended.

What do you think?

Best regards,
Frank

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/ORBit2/ChangeLog,v
retrieving revision 1.535
diff -u -r1.535 ChangeLog
--- ChangeLog	30 Jun 2003 15:52:53 -0000	1.535
+++ ChangeLog	30 Jun 2003 23:49:51 -0000
@@ -1,3 +1,17 @@
+2003-07-01  Frank Rehberger  <frehberg@localhost.localdomain>
+
+	* test/everything/client.c (testSequenceHelpers): extend test,
+	incremental resizing.
+
+	* src/orb/orb-core/corba-any.c (ORBit_sequence_append): fix
+	calculation for new_size in case of sequence-buffer of zero
+	capacity. Fixed calculation does not prevent SEGV. Must be some
+	problem with memory alignment.
+	(ORBit_sequence_alloc): add
+	ORBit_sequence_set_release(seq,CORBA_TRUE), otherwise buffer will
+	not be CORBA_free'd, allocated sequence has length 0 instead of
+	set to max capacity.
+
 2003-06-30  Padraig O'Briain <padraig.obriain@sun.com>
 
 	* linc2/src/linc-connection.c: Move link_source_remove and 
Index: src/orb/orb-core/corba-any.c
===================================================================
RCS file: /cvs/gnome/ORBit2/src/orb/orb-core/corba-any.c,v
retrieving revision 1.51
diff -u -r1.51 corba-any.c
--- src/orb/orb-core/corba-any.c	31 Mar 2003 08:59:52 -0000	1.51
+++ src/orb/orb-core/corba-any.c	30 Jun 2003 23:49:51 -0000
@@ -1165,8 +1165,10 @@
 	
 	seq = ORBit_alloc_by_tc (sequence_tc);
 	seq->_buffer = ORBit_small_allocbuf (tc, length);
-	seq->_length = length;
+	seq->_length  = 0;
 	seq->_maximum = length;
+	
+	CORBA_sequence_set_release (seq, CORBA_TRUE);
 
 	g_assert (ORBit_alloc_get_tcval (seq) == sequence_tc);
 
@@ -1241,11 +1243,14 @@
 	g_return_if_fail (tc->kind == CORBA_tk_sequence);
 
 	if (seq->_length == seq->_maximum) {
+		/* take care for _maximum==0 */ 
+		guint new_len = MAX (2, (seq->_maximum * 2));
+
 		/* NB. extend maximum, not length */
 		seq->_buffer = ORBit_realloc_tcval
 			(seq->_buffer, subtc,
-			 seq->_maximum, seq->_maximum * 2);
-		seq->_maximum *= 2;
+			 seq->_maximum, new_len );
+		seq->_maximum = new_len;
 	}
 
 	element_size = ORBit_gather_alloc_info (subtc);
Index: test/everything/client.c
===================================================================
RCS file: /cvs/gnome/ORBit2/test/everything/client.c,v
retrieving revision 1.106
diff -u -r1.106 client.c
--- test/everything/client.c	24 Jun 2003 16:56:17 -0000	1.106
+++ test/everything/client.c	30 Jun 2003 23:49:52 -0000
@@ -67,11 +67,12 @@
 testSequenceHelpers (void)
 {
 	CORBA_long l;
-	test_BoundedLongSeq *lseq;
+	test_BoundedLongSeq        *lseq = NULL;
+	
 
 	lseq = ORBit_sequence_alloc (TC_test_BoundedLongSeq, 2);
 	g_assert (lseq != NULL);
-	g_assert (lseq->_length == 2);
+	g_assert (lseq->_length ==  0);
 	g_assert (lseq->_maximum >= 2);
 
 	l = 1;
@@ -79,14 +80,41 @@
 	l++;
 	ORBit_sequence_append (lseq, &l);
 	
-	g_assert (lseq->_length == 4);
-	g_assert (ORBit_sequence_index (lseq, 2) == 1);
-	g_assert (ORBit_sequence_index (lseq, 3) == 2);
+	g_assert (lseq->_length == 2);
+	g_assert (ORBit_sequence_index (lseq, 0) == 1);
+	g_assert (ORBit_sequence_index (lseq, 1) == 2);
 
 	ORBit_sequence_set_size (lseq, 100);
 	ORBit_sequence_set_size (lseq, 0);
 
 	CORBA_free (lseq);
+
+	/* test incremental reallocation of memory */
+	{
+		/* 16 times double capacity of buffer */
+		CORBA_long MAX_APPEND = 1<<16; 
+		/* generic sequence<octet> test */ 
+		CORBA_sequence_CORBA_octet *oseq = NULL;
+		
+		g_warning ("FIXME, append to sequences of capacity=0 fails ");
+		oseq = ORBit_sequence_alloc (TC_CORBA_sequence_CORBA_octet, 1);
+
+		g_assert (oseq != NULL);
+		g_assert (oseq->_length == 0);
+		g_assert (oseq->_maximum >= 0);
+
+		for (l = 0; l < MAX_APPEND; ++l)
+		{
+			CORBA_octet oct = (CORBA_octet) (l % 128);
+			ORBit_sequence_append (oseq, &oct); /* realloc */ 
+
+			g_assert (l+1==oseq->_length);
+		}
+		
+		CORBA_free (oseq);
+	}
+
+	g_warning ("FIXME, check ORBit_sequence* family for memory leaks");
 }
 
 static void


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