|
From: Leeland A. <la...@re...> - 2011-11-08 02:56:27
|
Hello,
We are using OpenDDS version 2.3-RT14855-1, on Ubuntu 10.04.3.
We have discovered what looks like a memory leak in the OpenDDS generated
code for DCS_DataTypeSupportImpl.cpp. For various certification reasons
moving up to the current version of OpenDDS isn’t an option for at least 6
months.
I suspect we just might not be using the library correctly. I would greatly
appreciate any pointers or ideas.
Thanks in advance!
This is a memory usage analysis over a long run of our code and it shows
this same area as ever increasing at a rate of about 3.15KB/second.
->56.63% (28,906,414B) 0x5C85186: ACE_New_Allocator::malloc(unsigned int)
(Malloc_Allocator.cpp:118)
| ->55.99% (28,581,369B) 0x5C8BE66: ACE_Data_Block::ACE_Data_Block(unsigned
int, int, char const*, ACE_Allocator*, ACE_Lock*, unsigned long,
ACE_Allocator*) (Message_Block.cpp:368)
| | ->55.99% (28,581,369B) 0x5C8D240: ACE_Message_Block::init_i(unsigned
int, int, ACE_Message_Block*, char const*, ACE_Allocator*, ACE_Lock*,
unsigned long, unsigned long, ACE_Time_Value const&, ACE_Time_Value const&,
ACE_Data_Block*, ACE_Allocator*, ACE_Allocator*) (Message_Block.cpp:727)
| | ->55.99% (28,581,369B) 0x5C8C4BC:
ACE_Message_Block::ACE_Message_Block(unsigned int, int, ACE_Message_Block*,
char const*, ACE_Allocator*, ACE_Lock*, unsigned long, ACE_Time_Value
const&, ACE_Time_Value const&, ACE_Allocator*, ACE_Allocator*)
(Message_Block.cpp:453)
| | ->55.99% (28,579,608B) 0x4D7402B:
DCS::SampleBinMsgDataWriterImpl::dds_marshal(DCS::SampleBinMsg const&, int)
(DCS_DataTypeSupportImpl.cpp:5411)
| | | ->55.99% (28,579,608B) 0x4D7340B:
DCS::SampleBinMsgDataWriterImpl::write_w_timestamp(DCS::SampleBinMsg
const&, int, DDS::Time_t const&) (DCS_DataTypeSupportImpl.cpp:5211)
| | | ->55.99% (28,579,608B) 0x4D732CA:
DCS::SampleBinMsgDataWriterImpl::write(DCS::SampleBinMsg const&, int)
(DCS_DataTypeSupportImpl.cpp:5168)
| | | ->55.99% (28,579,608B) 0x4DCB2A1:
DCS_DDSWriter::send_dcs_data(DCS::SampleBinMsg*) (DCS_Svc_DDSStack.cpp:986)
| | | ->55.99% (28,579,608B) 0x4DCAB76:
DCS_DDSWriter::send_data(s5w::SampleBinMsg const&)
(DCS_Svc_DDSStack.cpp:882)
| | | ->55.99% (28,579,608B) 0x808492B:
s5w::Concentrator::latsFeeder() (latsFeeder.cpp:35)
The call we are making essentially pulls a message from a std::deque and
feeds it into DCS_DDSWriter::send_data().
The data description in the DCS_Data.idl file is
struct SampleBinMsg {
UuIdType id_; //used for DDS topic key keys
long ttlSeconds_;
string source_;
SampleBin bin_;
TimeStamp cnFwdTime_;
unsigned long recipient_;
};
Here is the relavent code around the "leak":
latsFeeder.cpp:35
[...]
SampleBin::SPtr bp(sampleMsgHandler.bins().pop());
bp->validatePayloadData(concConfig_.usePayloadValidFlag());
SampleBinMsg msg(bp, TimeStamp());
dcs_writer_->send_data(msg); // line 35
[...]
DCS_Svc_DDSStack.cpp:882
bool DCS_DDSWriter::send_data(const s5w::SampleBinMsg& data_package)
{
bool is_successful = false;
DCS::SampleBinMsg* sample_bin = new DCS::SampleBinMsg();
if (0 != sample_bin) {
DCS_Svc_DDSStack::copyTo(*sample_bin, data_package); // line 882
is_successful = send_dcs_data(sample_bin);
}
else {
ACE_ERROR((LM_ERROR, "%P Failed to allocate memory sending
SampleBinMsg\n"));
is_successful = false;
}
return is_successful;
}
DCS_Svc_DDSStack.cpp:986
[...]
if (send_data) {
DCS::SampleBinMsgDataWriter_var package_writer =
DCS::SampleBinMsgDataWriter::_narrow(dw_);
DDS::ReturnCode_t result =
package_writer->write(*data_package, DDS::HANDLE_NIL); // line 986
is_successful = result == DDS::RETCODE_OK;
}
}
if (send_data) {
delete data_package;
}
return is_successful;
--- This is where the generated code from DDS comes into the picture:
DCS_DataTypeSupportImpl.cpp:5168
DDS::ReturnCode_t
SampleBinMsgDataWriterImpl::write (
const ::DCS::SampleBinMsg & instance_data,
::DDS::InstanceHandle_t handle)
ACE_THROW_SPEC ((CORBA::SystemException))
{
::DDS::Time_t const source_timestamp =
::OpenDDS::DCPS::time_value_to_time (ACE_OS::gettimeofday ());
return write_w_timestamp (instance_data,
handle,
source_timestamp); // line 5168
}
DCS_DataTypeSupportImpl.cpp:5211
DDS::ReturnCode_t
SampleBinMsgDataWriterImpl::write_w_timestamp (
const ::DCS::SampleBinMsg & instance_data,
::DDS::InstanceHandle_t handle,
const ::DDS::Time_t & source_timestamp)
ACE_THROW_SPEC ((CORBA::SystemException))
{
// A lock is obtained on entering this method to serialize access to
// the contained data storage and interfaces. This lock protects the
// marshaled data buffers as well as the instance data containers.
// This operation assumes the provided handle is valid. The handle
// provided will not be verified.
ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex,
guard,
get_lock (),
::DDS::RETCODE_ERROR);
if (handle == ::DDS::HANDLE_NIL)
{
::DDS::InstanceHandle_t registered_handle = ::DDS::HANDLE_NIL;
::DDS::ReturnCode_t ret
= this->get_or_create_instance_handle(registered_handle,
instance_data,
source_timestamp);
if (ret != ::DDS::RETCODE_OK)
{
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT("(%P|%t) ")
ACE_TEXT("SampleBinMsgDataWriterImpl::write, ")
ACE_TEXT("register failed err=%d.\n"),
ret),
ret);
}
handle = registered_handle;
}
ACE_Message_Block* const marshalled =
dds_marshal (instance_data); // FOR_WRITE - using cached // line 5211
// allocators
return OpenDDS::DCPS::DataWriterImpl::write(marshalled, handle,
source_timestamp);
}
DCS_DataTypeSupportImpl.cpp:5411
ACE_Message_Block*
SampleBinMsgDataWriterImpl::dds_marshal(
const ::DCS::SampleBinMsg& instance_data,
int for_write)
{
ACE_Message_Block* mb;
if (for_write)
{
ACE_NEW_MALLOC_RETURN (mb, // line 5411
static_cast<ACE_Message_Block*> (
mb_allocator_->malloc (
sizeof (ACE_Message_Block))),
ACE_Message_Block(
marshaled_size_ ? marshaled_size_ :
OpenDDS::DCPS::gen_find_size(instance_data),
ACE_Message_Block::MB_DATA,
0, //cont
0, //data
data_allocator_, //allocator_strategy
db_lock_pool_->get_lock(), //data block
locking_strategy
ACE_DEFAULT_MESSAGE_BLOCK_PRIORITY,
ACE_Time_Value::zero,
ACE_Time_Value::max_time,
db_allocator_,
mb_allocator_),
0);
}
else
{ // Don't use the cached allocator for the registered sample message
// block.
ACE_NEW_RETURN (mb,
ACE_Message_Block(marshaled_size_
? marshaled_size_
:
OpenDDS::DCPS::gen_find_size(instance_data)),
0);
}
::OpenDDS::DCPS::Serializer serializer (mb,
this->get_publisher_servant()->swap_bytes());
serializer << instance_data;
return mb;
}
+ Leeland
|