this patch fixes a serious memory leaks. The problem was that the TypeCode
for CORBA_any
is always initialized with -1, sot that it never get released.
I have also implemented NameValuePair sequences, which are needed by
the DynAny interface for structures (the new dynany code is not included
in this patch).
May I commit?
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 -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/02/28 07:59:34 @@ -353,7 +353,6 @@ ORBit_marshal_any(GIOPSendBuffer *buf, const CORBA_any *val) { ORBit_marshal_value_info mi; - gpointer mval = val->_value; ORBit_encode_CORBA_TypeCode(val->_type, buf); @@ -458,7 +457,7 @@ /* to allocate a block, we need to know of any important data contained in it. */ -static gpointer +gpointer ORBit_demarshal_allocate_mem(CORBA_TypeCode tc, gint nelements) { size_t block_size; @@ -474,7 +473,11 @@ GINT_TO_POINTER(nelements), sizeof(CORBA_TypeCode)); - *(CORBA_TypeCode *)((char *)retval-sizeof(ORBit_mem_info)-sizeof(CORBA_TypeCode)) = (CORBA_TypeCode)CORBA_Object_duplicate((CORBA_Object)tc, NULL); + if (ORBIT_ROOT_OBJECT(tc)->refs >= 0) + ORBIT_ROOT_OBJECT(tc)->refs += nelements; + + *(CORBA_TypeCode *)((char *)retval-sizeof(ORBit_mem_info)-sizeof(CORBA_TypeCode)) = tc; + } return retval; @@ -700,7 +703,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/corba_any.h =================================================================== RCS file: /cvs/gnome/ORBit/src/orb/corba_any.h,v retrieving revision 1.11 diff -u -r1.11 corba_any.h --- src/orb/corba_any.h 1999/11/07 01:12:30 1.11 +++ src/orb/corba_any.h 2001/02/28 07:59:34 @@ -42,4 +42,6 @@ void CORBA_any__copy(CORBA_any *out, CORBA_any *in); +gpointer ORBit_demarshal_allocate_mem(CORBA_TypeCode tc, gint nelements); + #endif /* !_ORBIT_CORBA_ANY_H_ */ Index: src/orb/corba_sequences.h =================================================================== RCS file: /cvs/gnome/ORBit/src/orb/corba_sequences.h,v retrieving revision 1.10 diff -u -r1.10 corba_sequences.h --- src/orb/corba_sequences.h 1999/09/20 15:42:27 1.10 +++ src/orb/corba_sequences.h 2001/02/28 07:59:34 @@ -42,7 +42,7 @@ typedef struct CORBA_sequence_ORB_ObjectId CORBA_ORB_ObjectIdList; #define _CORBA_sequence_NameValuePair_defined -typedef struct CORBA_sequence_NameValuePair CORBA_NameValuePairSeq; +typedef struct CORBA_sequence_NameValuePair CORBA_sequence_NameValuePair; #define _CORBA_sequence_CORBA_any_defined typedef struct CORBA_sequence_CORBA_any_struct CORBA_AnySeq; Index: src/orb/corba_typecode.h =================================================================== RCS file: /cvs/gnome/ORBit/src/orb/corba_typecode.h,v retrieving revision 1.10 diff -u -r1.10 corba_typecode.h --- src/orb/corba_typecode.h 1999/10/12 02:31:53 1.10 +++ src/orb/corba_typecode.h 2001/02/28 07:59:34 @@ -110,6 +110,7 @@ #define TC_string ((CORBA_TypeCode)&TC_string_struct) #define TC_wstring ((CORBA_TypeCode)&TC_wstring_struct) #define TC_CORBA_NamedValue ((CORBA_TypeCode)&TC_CORBA_NamedValue_struct) +#define TC_CORBA_NameValuePair ((CORBA_TypeCode)&TC_CORBA_NameValuePair_struct) #define TC_CORBA_short_struct TC_short_struct #define TC_CORBA_long_struct TC_long_struct @@ -158,6 +159,7 @@ extern const struct CORBA_TypeCode_struct TC_string_struct; extern const struct CORBA_TypeCode_struct TC_wstring_struct; extern const struct CORBA_TypeCode_struct TC_CORBA_NamedValue_struct; +extern const struct CORBA_TypeCode_struct TC_CORBA_NameValuePair_struct; #endif /* !_ORBIT_CORBA_TYPECODE_H_ */ Index: src/orb/orb.c =================================================================== RCS file: /cvs/gnome/ORBit/src/orb/orb.c,v retrieving revision 1.98.4.6 diff -u -r1.98.4.6 orb.c --- src/orb/orb.c 2001/01/20 22:02:23 1.98.4.6 +++ src/orb/orb.c 2001/02/28 07:59:35 @@ -1054,7 +1054,7 @@ &policies, ev); CORBA_Object_duplicate(orb->root_poa, ev); - CORBA_Object_release(policies._buffer[0],ev); + CORBA_Object_release((CORBA_Object)policies._buffer[0],ev); } return CORBA_Object_duplicate(orb->root_poa, ev); 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 -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/02/28 07:59:35 @@ -160,7 +160,7 @@ ctx.prior_tcs=NULL; tc_dec(t, codec, &ctx); for(l=ctx.prior_tcs;l;l=l->next) - g_free(l->data); + g_free(l->data); g_slist_free(ctx.prior_tcs); buf->cur = ((guchar *)buf->cur) + codec->rptr; } @@ -292,7 +292,7 @@ node=l->data; /* NOTE: below, -4 is b/c we already read offset */ if(node->index==ctx->current_idx+c->rptr+offset-4){ - *t=node->tc; + *t=CORBA_Object_duplicate ((CORBA_Object)node->tc, NULL); return; } } @@ -311,7 +311,6 @@ info=&tk_info[kind]; tc=g_new0(struct CORBA_TypeCode_struct, 1); - /* Passing in NULL for CORBA_Environment is patently dangerous. */ ORBit_pseudo_object_init((ORBit_PseudoObject)tc, ORBIT_PSEUDO_TYPECODE, NULL); @@ -320,7 +319,8 @@ NULL); tc->kind=kind; - ((ORBit_RootObject)tc)->refs=-1; /* negative so that it doesn't get freed by CORBA_Object_release() */ + ((ORBit_RootObject)tc)->refs= 1; + switch(info->type){ guint tmp_index; CORBA_octet o; @@ -375,7 +375,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 +411,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 +463,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); @@ -483,7 +480,6 @@ 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 +526,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 +552,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 +565,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/sequences.c =================================================================== RCS file: /cvs/gnome/ORBit/src/orb/sequences.c,v retrieving revision 1.8 diff -u -r1.8 sequences.c --- src/orb/sequences.c 1999/07/06 20:00:30 1.8 +++ src/orb/sequences.c 2001/02/28 07:59:35 @@ -1,5 +1,52 @@ #include "orbit.h" #include "sequences.h" +#include "corba_typecode.h" + +static const CORBA_TypeCode +CORBA_sequence_NameValuePair_subtypes_array [] = { + TC_CORBA_NameValuePair +}; + +static struct CORBA_TypeCode_struct +TC_CORBA_sequence_NameValuePair_struct = { + {{(ORBit_RootObject_Interface *) & ORBit_TypeCode_epv, TRUE, -1}, + ORBIT_PSEUDO_TYPECODE}, + + CORBA_tk_sequence, NULL, NULL, + 0, 1, + NULL, + (CORBA_TypeCode *) CORBA_sequence_NameValuePair_subtypes_array, + NULL, + CORBA_OBJECT_NIL, 0, -1, 0, 0 +}; + +CORBA_sequence_NameValuePair * +CORBA_sequence_NameValuePair__alloc (void) +{ + CORBA_sequence_NameValuePair *retval; + + retval = ORBit_demarshal_allocate_mem ( + &TC_CORBA_sequence_NameValuePair_struct, 1); + + retval->_maximum = 0; + retval->_length = 0; + retval->_buffer = NULL; + retval->_release = CORBA_FALSE; + + return retval; +} + +CORBA_NameValuePair * +CORBA_sequence_NameValuePair_allocbuf (CORBA_unsigned_long len) +{ + CORBA_NameValuePair *retval; + + retval = ORBit_demarshal_allocate_mem (TC_CORBA_NameValuePair, len); + + memset (retval, '\0', sizeof (CORBA_NameValuePair) * len); + + return retval; +} gpointer CORBA_sequence_octet_free(gpointer mem, gpointer func_data) Index: src/orb/sequences.h =================================================================== RCS file: /cvs/gnome/ORBit/src/orb/sequences.h,v retrieving revision 1.6 diff -u -r1.6 sequences.h --- src/orb/sequences.h 1998/07/29 22:11:54 1.6 +++ src/orb/sequences.h 2001/02/28 07:59:35 @@ -28,8 +28,11 @@ /* #include "corba_sequences_type.h" */ #include "orbit_types.h" +#include "corba_sequences.h" CORBA_octet *CORBA_octet_allocbuf(CORBA_unsigned_long len); CORBA_sequence_octet *CORBA_sequence_octet__alloc(void); +CORBA_NameValuePair *CORBA_sequence_NameValuePair_allocbuf(CORBA_unsigned_long len); +CORBA_sequence_NameValuePair *CORBA_sequence_NameValuePair__alloc(void); #endif /* !_ORBIT_SEQUENCES_H_ */ Index: src/orb/typecode.c =================================================================== RCS file: /cvs/gnome/ORBit/src/orb/typecode.c,v retrieving revision 1.14 diff -u -r1.14 typecode.c --- src/orb/typecode.c 1999/10/27 20:02:46 1.14 +++ src/orb/typecode.c 2001/02/28 07:59:35 @@ -72,6 +72,26 @@ const struct CORBA_TypeCode_struct TC_CORBA_NamedValue_struct= {{{(ORBit_RootObject_Interface *)&ORBit_TypeCode_epv, CORBA_FALSE, -1}, ORBIT_PSEUDO_TYPECODE}, CORBA_tk_struct, "CORBA NamedValue", "", 0, 0, NULL, NULL, NULL, NULL, -1, 0, 0, 0}; +static const char *anon_subnames_array8[] = { "id", "value" }; + +static const CORBA_TypeCode anon_subtypes_array8[] = +{(CORBA_TypeCode) & TC_CORBA_string_struct, +(CORBA_TypeCode) & TC_CORBA_any_struct}; + +const struct CORBA_TypeCode_struct +TC_CORBA_NameValuePair_struct = { + {{(ORBit_RootObject_Interface *) & ORBit_TypeCode_epv, TRUE, -1}, + ORBIT_PSEUDO_TYPECODE}, + + CORBA_tk_struct, "NameValuePair", + "IDL:omg.org/CORBA/NameValuePair:1.0", + 0, 2, + (const char **) anon_subnames_array8, + (CORBA_TypeCode *) anon_subtypes_array8, + NULL, + CORBA_OBJECT_NIL, 0, -1, 0, 0 +}; + static const CORBA_TypeCode anon_subtypes_array7[] = {(CORBA_TypeCode) & TC_CORBA_string_struct}; 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 -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/02/28 07:59:35 @@ -350,6 +350,9 @@ case IDLN_INTERFACE: case IDLN_FORWARD_DCL: fprintf(ci->fh, "if(ev->_major == CORBA_NO_EXCEPTION) CORBA_Object_release(_ORBIT_retval, ev);\n"); + return; + case IDLN_TYPE_TYPECODE: + fprintf(ci->fh, "if(ev->_major == CORBA_NO_EXCEPTION) CORBA_Object_release((CORBA_Object)_ORBIT_retval, ev);\n"); default: return; } @@ -411,7 +414,7 @@ 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, TRUE); break; case IDLN_TYPE_OBJECT: case IDLN_INTERFACE: @@ -430,9 +433,9 @@ fprintf(ci->fh, "if(ev->_major == CORBA_NO_EXCEPTION)"); switch(IDL_NODE_TYPE(ts)) { case IDLN_TYPE_OBJECT: - case IDLN_FORWARD_DCL: + case IDLN_FORWARD_DCL: case IDLN_INTERFACE: - case IDLN_TYPE_TYPECODE: + case IDLN_TYPE_TYPECODE: fprintf(ci->fh, "CORBA_Object_release((CORBA_Object)%s, ev);\n", IDL_IDENT(IDL_PARAM_DCL(tree).simple_declarator).str); break; @@ -447,7 +450,7 @@ switch(IDL_NODE_TYPE(ts)) { case IDLN_TYPE_OBJECT: case IDLN_INTERFACE: - case IDLN_TYPE_TYPECODE: + case IDLN_TYPE_TYPECODE: fprintf(ci->fh, "CORBA_Object_release((CORBA_Object)%s, ev);\n", IDL_IDENT(IDL_PARAM_DCL(tree).simple_declarator).str); break;