string sequence memory handling weirdness



Hi,

This might seem like a very stupid question, but I really can't see any
reason in what I've seen. I have a helper function to release memory
within string sequences. It goes like this:

void 
brutus_free_seq_string_content(BRUTUS_seq_string *strings)
{
	int n;

	if (!strings)
		return;

	for (n = 0; n < strings->_length; n++)
		CORBA_free(strings->_buffer[n]);
	CORBA_free(strings->_buffer);

	strings->_maximum = 0;
	strings->_length = 0;
	strings->_buffer = NULL;
}

BRUTUS_seq_string is a typedef in the BRUTUS namespace:

    typedef sequence<string> seq_string; 

Memory has been allocated to a string sequence like this:

    name_fields._maximum = 2;
    name_fields._length = name_fields._maximum;
    name_fields._buffer = BRUTUS_seq_string_allocbuf(name_fields._maximum);
    name_fields._buffer[0] = CORBA_string_dup("Reply-To");
    name_fields._buffer[1] = CORBA_string_dup("Content-MD5");

The "name_fields" variable is subsequently used as an "in" parameter to
a CORBA method.  The problem is that I get a double free exception from
glibc when I invoke brutus_free_seq_string_content() on &name_fields
after it has been used. 

The error comes from this line:

	CORBA_free(strings->_buffer);

Why on earth is this happening? Does the CORBA method free the _buffer or what?


Thanks a lot in advance,
  jules




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