[Ace-users] [tao-bugs]Memeroy leaks when ORB::run is called from a
thread, different from the one that did the ORB_init
wind
xuqp1979 at hotmail.com
Sat Sep 29 21:56:19 CDT 2007
TAO VERSION: 1.6
ACE VERSION: 5.6
HOST MACHINE and OPERATING SYSTEM:
If on Windows based OS's, which version of WINSOCK do you
use?:
//=
Windows XP SP2 VC71
//=
THE $ACE_ROOT/ace/config.h FILE [if you use a link to a platform-
specific file, simply state which one]:
//=
#include "ace/config-win32.h"
//=
AREA/CLASS/EXAMPLE AFFECTED:
//=
ACE_TSS<TYPE>
ACE_Service_Config
ACE_Service_Config_Guard
TAO_ORB_Core
TAO_POA_Static_Resources::instance()
//=
SYNOPSIS:
[Brief description of the problem]
//=
Memeroy leaks when ORB::run is called from a thread, different
from the one that did the ORB_init
//=
DESCRIPTION:
[Detailed description of problem. Don't just say "<blah>
doesn't work, here's a fix," explain what your program does
to get to the <blah> state. ]
//=
Memeroy leaks when ORB::run is called from a thread, different
from the one that did the ORB_init.Here is the Vc71 Output:
{922} normal block at 0x00E44658, 4096 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD
CD CD CD CD CD
{921} normal block at 0x00E445F0, 40 bytes long.
Data: <XF > 58 46 E4 00 00 00 00 00 00 04 00
00 E0 F3 14 00
{920} normal block at 0x00E44588, 44 bytes long.
Data: <tt > 74 74 17 10 01 CD CD CD 00 04 00
00 00 00 00 00
{428} normal block at 0x00E1E608, 19 bytes long.
Data: <ImR_Client_Adapt> 49 6D 52 5F 43 6C 69 65 6E 74 5F
41 64 61 70 74
{427} normal block at 0x00E18FD8, 20 bytes long.
Data: <ORT_Adapter_Fact> 4F 52 54 5F 41 64 61 70 74 65 72
5F 46 61 63 74
{426} normal block at 0x00E18F70, 40 bytes long.
Data: <0 > 30 F9 20 10 13 00 00 00 14 00 00
00 D8 8F E1 00
the reason for {426},{427},{428} memory leak is that when
program is exited the TAO_POA_Static_Resources::instan ce() isn't realeased.
the readon for {426},{427},{428} memory leak is when ORB::run
is called from a new thread,a new ACE_TSS<ACE_Service_Gestalt> is created in
TAO_ORB_Core::run()method:
ACE_Service_Config_Guard use_orbs (this->configuration());
(ace_wrappers\tao\tao\orb_core.cpp:2078)
but the new ACE_TSS<ACE_Service_Gestalt> instance related to
the ORB::run thread isn't released when the thread exits,
//=
REPEAT BY:
[What you did to get the error; include test program or session
transcript if at all possible. ]
//=
#include "ace/Task.h"
#include "tao/ORB_Core.h"
#include "tao/PortableServer/Root_POA.h"
#include <sstream>
#include <iostream>
/**
* @brief ORB Message Loop Task
*/
class ORBMessageLoopTask: public ACE_Task_Base
{
public:
/**
* @brief Start ORB message loop
*
* @param args CORBA#ORB instance
*
* @exception std#exception
*/
virtual int open(void* args)
{
m_orb = CORBA::ORB::_duplicate((CORBA::ORB_ptr)args);
ACE_ASSERT(!CORBA::is_nil(m_orb));
return activate();
}
/// ORB message loop
virtual int svc(void)
{
try{
// ORB::run is called from a thread, different from the one that
// did the ORB_init
m_orb->run();
}
catch(const CORBA::Exception& ex)
{
std::cerr << "ORB run failed : " << ex << std::endl;
return -1;
}
return 0;
}
private:
/// the ORB instance
CORBA::ORB_var m_orb;
};
/**
* @brief Console loop
*/
void MainLoopInConsole();
/**
* @brief Console loop
*/
int main(int argc,char * argv[])
{
#ifdef _WIN32
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
using namespace std;
try {
// Initialize the ORB in main thread.
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
// Start ORB message loop in other thread
ORBMessageLoopTask orbTask;
orbTask.open(orb);
// Console loop
MainLoopInConsole();
// instructs the ORB to shut down
orb->shutdown(true);
orbTask.wait();
orb->destroy();
}
catch(const CORBA::Exception& e) {
cerr << e << endl;
return 1;
}
return 0;
}
/**
* @brief Console loop
*/
void MainLoopInConsole()
{
std::ostringstream lastCommand;
bool canExit = false;
std::string cmdOptions =
" X: eXit \r\n"
" O: display Options \r\n"
" ==========================================================\r\n";
while(!canExit)
{
#ifndef _WIN32
ACE_OS::system("clear");
#else
ACE_OS::system("cls");
#endif
std::cout << "
==========================================================\r\n"
" CORBA ORB Run Demo - version 1.0\r\n"
" \r\n"
" please select:\r\n";
std::cout << cmdOptions;
std::cout << lastCommand.str();
std::cout << " \r\n ";
std::cout << " > ";
int i = getchar();
switch(i)
{
case 'X':
case 'x':
std::cout << "Server is exiting ,please wait...\r\n";
canExit = true;
break;
case 'O':
case 'o':
lastCommand.str("");
lastCommand << "Options: \r\n";
lastCommand << cmdOptions;
break;
case '\n':
case '\r':
case ' ':
case '\t':
break;
default:
lastCommand.str("");
lastCommand << "Invalid command: " << (char)i << " \r\n";
break;
}
}
}
//=
SAMPLE FIX/WORKAROUND:
[If available ]
More information about the Ace-users
mailing list