Commit 9e8d9030 authored by Pavel Vainerman's avatar Pavel Vainerman

(9) Попытка решить проблеммы с утчечками памяти.

parent 71691352
...@@ -597,25 +597,22 @@ void SharedMemory::checkHistoryFilter( UniXML::iterator& xit ) ...@@ -597,25 +597,22 @@ void SharedMemory::checkHistoryFilter( UniXML::iterator& xit )
if( xit.getProp(it.filter).empty() ) if( xit.getProp(it.filter).empty() )
continue; continue;
HistoryItem ai;
if( !xit.getProp("id").empty() ) if( !xit.getProp("id").empty() )
{ {
ai.id = xit.getIntProp("id"); HistoryItem ai(xit.getIntProp("id"), it.size, xit.getIntProp("default") );
ai.init( it.size, xit.getIntProp("default") ); it.hlst.push_back( std::move(ai) );
it.hlst.push_back(ai);
continue; continue;
} }
ai.id = uniset_conf()->getSensorID(xit.getProp("name")); ObjectId id = uniset_conf()->getSensorID(xit.getProp("name"));
if( ai.id == DefaultObjectId ) if( id == DefaultObjectId )
{ {
dwarn << myname << "(checkHistoryFilter): not found sensor ID for " << xit.getProp("name") << endl; dwarn << myname << "(checkHistoryFilter): not found sensor ID for " << xit.getProp("name") << endl;
continue; continue;
} }
ai.init( it.size, xit.getIntProp("default") ); HistoryItem ai(id, it.size, xit.getIntProp("default") );
it.hlst.push_back(ai); it.hlst.push_back( std::move(ai) );
} }
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
...@@ -277,7 +277,8 @@ class SharedMemory: ...@@ -277,7 +277,8 @@ class SharedMemory:
struct HistoryItem struct HistoryItem
{ {
HistoryItem():id(UniSetTypes::DefaultObjectId){} HistoryItem( size_t bufsize=0 ):id(UniSetTypes::DefaultObjectId),buf(bufsize){}
HistoryItem( const UniSetTypes::ObjectId _id, const size_t bufsize, const long val ):id(_id),buf(bufsize,val){}
inline void init( unsigned int size, long val ) inline void init( unsigned int size, long val )
{ {
......
...@@ -160,8 +160,8 @@ namespace UniSetTypes ...@@ -160,8 +160,8 @@ namespace UniSetTypes
/*! указатель на конфигурационный xml */ /*! указатель на конфигурационный xml */
inline const std::shared_ptr<UniXML> getConfXML() const { return unixml; } inline const std::shared_ptr<UniXML> getConfXML() const { return unixml; }
CORBA::ORB_ptr getORB()const { return CORBA::ORB::_duplicate(orb); } inline CORBA::ORB_ptr getORB() const { return CORBA::ORB::_duplicate(orb); }
CORBA::PolicyList getPolicy() const { return policyList; } inline const CORBA::PolicyList getPolicy() const { return policyList; }
protected: protected:
Configuration(); Configuration();
......
...@@ -331,6 +331,9 @@ class IONotifyController: ...@@ -331,6 +331,9 @@ class IONotifyController:
UniSetTypes::uniset_rwmutex trshMutex; UniSetTypes::uniset_rwmutex trshMutex;
int maxAttemtps; /*! timeout for consumer */ int maxAttemtps; /*! timeout for consumer */
sigc::connection conInit;
sigc::connection conUndef;
}; };
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#endif #endif
......
...@@ -188,7 +188,7 @@ public: ...@@ -188,7 +188,7 @@ public:
xmlNode* cur; xmlNode* cur;
xmlDoc* doc; xmlDoc* doc;
std::string filename; inline std::string getFileName(){ return filename; }
// Создать новый XML-документ // Создать новый XML-документ
void newDoc(const std::string& root_node, std::string xml_ver="1.0"); void newDoc(const std::string& root_node, std::string xml_ver="1.0");
...@@ -235,6 +235,8 @@ public: ...@@ -235,6 +235,8 @@ public:
protected: protected:
std::string filename;
// Преобразование текстовой строки из XML в строку нашего внутреннего представления // Преобразование текстовой строки из XML в строку нашего внутреннего представления
static std::string xml2local( const std::string& text ); static std::string xml2local( const std::string& text );
......
...@@ -180,10 +180,9 @@ unsigned int ObjectIndex_XML::read_section( const std::shared_ptr<UniXML>& xml, ...@@ -180,10 +180,9 @@ unsigned int ObjectIndex_XML::read_section( const std::shared_ptr<UniXML>& xml,
// name // name
ostringstream n; ostringstream n;
n << secname << xml->getProp(it,"name"); n << secname << xml->getProp(it,"name");
const string name(n.str());
delete[] omap[ind].repName; delete[] omap[ind].repName;
omap[ind].repName = new char[name.size()+1]; const string name(n.str());
strcpy( omap[ind].repName, name.c_str() ); omap[ind].repName = uni_strdup(name);
// mok // mok
mok[name] = ind; // mok[omap[ind].repName] = ind; mok[name] = ind; // mok[omap[ind].repName] = ind;
...@@ -194,8 +193,7 @@ unsigned int ObjectIndex_XML::read_section( const std::shared_ptr<UniXML>& xml, ...@@ -194,8 +193,7 @@ unsigned int ObjectIndex_XML::read_section( const std::shared_ptr<UniXML>& xml,
textname = xml->getProp(it,"name"); textname = xml->getProp(it,"name");
delete[] omap[ind].textName; delete[] omap[ind].textName;
omap[ind].textName = new char[textname.size()+1]; omap[ind].textName = uni_strdup(textname);
strcpy( omap[ind].textName, textname.c_str() );
omap[ind].data = (void*)(xmlNode*)it; omap[ind].data = (void*)(xmlNode*)it;
...@@ -249,8 +247,7 @@ unsigned int ObjectIndex_XML::read_nodes( const std::shared_ptr<UniXML>& xml, co ...@@ -249,8 +247,7 @@ unsigned int ObjectIndex_XML::read_nodes( const std::shared_ptr<UniXML>& xml, co
string nodename(xml->getProp(it,"name")); string nodename(xml->getProp(it,"name"));
delete[] omap[ind].repName; delete[] omap[ind].repName;
omap[ind].repName = new char[nodename.size()+1]; omap[ind].repName = uni_strdup(nodename);
strcpy( omap[ind].repName, nodename.c_str() );
// textname // textname
string textname(xml->getProp(it,"textname")); string textname(xml->getProp(it,"textname"));
...@@ -258,9 +255,7 @@ unsigned int ObjectIndex_XML::read_nodes( const std::shared_ptr<UniXML>& xml, co ...@@ -258,9 +255,7 @@ unsigned int ObjectIndex_XML::read_nodes( const std::shared_ptr<UniXML>& xml, co
textname = nodename; textname = nodename;
delete[] omap[ind].textName; delete[] omap[ind].textName;
omap[ind].textName = new char[textname.size()+1]; omap[ind].textName = uni_strdup(textname);
strcpy( omap[ind].textName, textname.c_str() );
omap[ind].data = (void*)(xmlNode*)(it); omap[ind].data = (void*)(xmlNode*)(it);
// //
mok[omap[ind].repName] = ind; mok[omap[ind].repName] = ind;
......
...@@ -149,23 +149,18 @@ void ObjectIndex_idXML::read_section( const std::shared_ptr<UniXML>& xml, const ...@@ -149,23 +149,18 @@ void ObjectIndex_idXML::read_section( const std::shared_ptr<UniXML>& xml, const
// name // name
ostringstream n; ostringstream n;
n << secname << it.getProp("name"); n << secname << it.getProp("name");
string name(n.str()); const string name(n.str());
inf.repName = uni_strdup(name);
inf.repName = new char[name.size()+1];
strcpy( inf.repName, name.c_str() );
// textname
string textname(xml->getProp(it,"textname")); string textname(xml->getProp(it,"textname"));
if( textname.empty() ) if( textname.empty() )
textname = xml->getProp(it,"name"); textname = xml->getProp(it,"name");
inf.textName = new char[textname.size()+1]; inf.textName = uni_strdup(textname);
strcpy( inf.textName, textname.c_str() );
inf.data = (void*)(xmlNode*)(it); inf.data = (void*)(xmlNode*)(it);
omap.insert(MapObjects::value_type(inf.id,inf)); // omap[inf.id] = inf;
mok.insert(MapObjectKey::value_type(name,inf.id)); // mok[name] = inf.id; mok.insert(MapObjectKey::value_type(name,inf.id)); // mok[name] = inf.id;
omap.insert(MapObjects::value_type(inf.id, std::move(inf))); // omap[inf.id] = inf;
} }
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
...@@ -202,18 +197,14 @@ void ObjectIndex_idXML::read_nodes( const std::shared_ptr<UniXML>& xml, const st ...@@ -202,18 +197,14 @@ void ObjectIndex_idXML::read_nodes( const std::shared_ptr<UniXML>& xml, const st
} }
string name(it.getProp("name")); string name(it.getProp("name"));
inf.repName = uni_strdup(name);
inf.repName = new char[name.size()+1];
strcpy( inf.repName, name.c_str() );
// textname // textname
string textname(xml->getProp(it,"textname")); string textname(xml->getProp(it,"textname"));
if( textname.empty() ) if( textname.empty() )
textname = name; textname = name;
inf.textName = new char[textname.size()+1]; inf.textName = uni_strdup(textname);
strcpy( inf.textName, textname.c_str() );
inf.data = (void*)(xmlNode*)(it); inf.data = (void*)(xmlNode*)(it);
omap.insert(MapObjects::value_type(inf.id,inf)); // omap[inf.id] = inf; omap.insert(MapObjects::value_type(inf.id,inf)); // omap[inf.id] = inf;
......
...@@ -126,7 +126,7 @@ void UniSetActivator::init() ...@@ -126,7 +126,7 @@ void UniSetActivator::init()
CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj); PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
pman = root_poa->the_POAManager(); pman = root_poa->the_POAManager();
CORBA::PolicyList pl = conf->getPolicy(); const CORBA::PolicyList pl = conf->getPolicy();
poa = root_poa->create_POA("my poa", pman, pl); poa = root_poa->create_POA("my poa", pman, pl);
if( CORBA::is_nil(poa) ) if( CORBA::is_nil(poa) )
...@@ -410,7 +410,11 @@ void UniSetActivator::sysCommand( const UniSetTypes::SystemMessage *sm ) ...@@ -410,7 +410,11 @@ void UniSetActivator::sysCommand( const UniSetTypes::SystemMessage *sm )
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void UniSetActivator::set_signals(bool ask) void UniSetActivator::set_signals(bool ask)
{ {
struct sigaction act, oact; struct sigaction act; // = { { 0 } };
struct sigaction oact; // = { { 0 } };
memset(&act,0,sizeof(act));
memset(&act,0,sizeof(oact));
sigemptyset(&act.sa_mask); sigemptyset(&act.sa_mask);
sigemptyset(&oact.sa_mask); sigemptyset(&oact.sa_mask);
......
...@@ -65,8 +65,8 @@ IONotifyController::IONotifyController( ObjectId id, NCRestorer* d ): ...@@ -65,8 +65,8 @@ IONotifyController::IONotifyController( ObjectId id, NCRestorer* d ):
trshMutex(string(uniset_conf()->oind->getMapName(id))+"_trshMutex"), trshMutex(string(uniset_conf()->oind->getMapName(id))+"_trshMutex"),
maxAttemtps(uniset_conf()->getPIntField("ConsumerMaxAttempts", 5)) maxAttemtps(uniset_conf()->getPIntField("ConsumerMaxAttempts", 5))
{ {
signal_change_undefined_state().connect(sigc::mem_fun(*this, &IONotifyController::onChangeUndefinedState)); conUndef = signal_change_undefined_state().connect(sigc::mem_fun(*this, &IONotifyController::onChangeUndefinedState));
signal_init().connect(sigc::mem_fun(*this, &IONotifyController::initItem)); conInit = signal_init().connect(sigc::mem_fun(*this, &IONotifyController::initItem));
// добавляем фильтры // добавляем фильтры
addIOFilter( sigc::mem_fun(this,&IONotifyController::myIOFilter) ); addIOFilter( sigc::mem_fun(this,&IONotifyController::myIOFilter) );
...@@ -74,6 +74,8 @@ IONotifyController::IONotifyController( ObjectId id, NCRestorer* d ): ...@@ -74,6 +74,8 @@ IONotifyController::IONotifyController( ObjectId id, NCRestorer* d ):
IONotifyController::~IONotifyController() IONotifyController::~IONotifyController()
{ {
conUndef.disconnect();
conInit.disconnect();
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
......
...@@ -159,8 +159,7 @@ void NCRestorer::init_depends_signals( IONotifyController* ic ) ...@@ -159,8 +159,7 @@ void NCRestorer::init_depends_signals( IONotifyController* ic )
<< " dep_name=(" << it->second.d_si.id << ")'" << uniset_conf()->oind->getMapName(it->second.d_si.id) << "'" << " dep_name=(" << it->second.d_si.id << ")'" << uniset_conf()->oind->getMapName(it->second.d_si.id) << "'"
<< endl; << endl;
IOController::ChangeSignal s = ic->signal_change_value(it->second.d_si.id); ic->signal_change_value(it->second.d_si.id).connect( sigc::mem_fun( &it->second, &IOController::USensorInfo::checkDepend) );
s.connect( sigc::mem_fun( &it->second, &IOController::USensorInfo::checkDepend) );
} }
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -40,7 +40,7 @@ c_filterValue(""), ...@@ -40,7 +40,7 @@ c_filterValue(""),
t_filterField(""), t_filterField(""),
t_filterValue(""), t_filterValue(""),
fname(fname), fname(fname),
uxml(0) uxml(nullptr)
{ {
init(fname); init(fname);
} }
...@@ -55,7 +55,7 @@ c_filterValue(""), ...@@ -55,7 +55,7 @@ c_filterValue(""),
t_filterField(""), t_filterField(""),
t_filterValue(""), t_filterValue(""),
fname(fname), fname(fname),
uxml(0) uxml(nullptr)
{ {
init(fname); init(fname);
setItemFilter(f_field,f_value); setItemFilter(f_field,f_value);
...@@ -63,7 +63,7 @@ uxml(0) ...@@ -63,7 +63,7 @@ uxml(0)
NCRestorer_XML::NCRestorer_XML(): NCRestorer_XML::NCRestorer_XML():
fname(""), fname(""),
uxml(0) uxml(nullptr)
{ {
} }
...@@ -77,7 +77,7 @@ NCRestorer_XML::~NCRestorer_XML() ...@@ -77,7 +77,7 @@ NCRestorer_XML::~NCRestorer_XML()
} }
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
void NCRestorer_XML::init( const std::string& fname ) void NCRestorer_XML::init( const std::string& xmlfile )
{ {
/*! /*!
\warning Файл открывается только при создании... \warning Файл открывается только при создании...
...@@ -85,14 +85,22 @@ void NCRestorer_XML::init( const std::string& fname ) ...@@ -85,14 +85,22 @@ void NCRestorer_XML::init( const std::string& fname )
*/ */
try try
{ {
if( fname == uniset_conf()->getConfFileName() ) if( xmlfile == uniset_conf()->getConfFileName() )
uxml = uniset_conf()->getConfXML(); uxml = uniset_conf()->getConfXML();
else else
uxml = make_shared<UniXML>(fname); {
if( uxml )
{
uxml->close();
uxml.reset();
}
uxml = make_shared<UniXML>(xmlfile);
}
fname = xmlfile;
} }
catch( UniSetTypes::NameNotFound& ex ) catch( UniSetTypes::NameNotFound& ex )
{ {
uwarn << "(NCRestorer_XML): файл " << fname << " не найден, создаём новый...\n"; uwarn << "(NCRestorer_XML): файл " << xmlfile << " не найден, создаём новый...\n";
} }
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
...@@ -180,9 +188,9 @@ void NCRestorer_XML::read( IONotifyController* ic, const string& fn ) ...@@ -180,9 +188,9 @@ void NCRestorer_XML::read( IONotifyController* ic, const string& fn )
else if( !fname.empty() ) else if( !fname.empty() )
{ {
// оптимизация (не загружаем второй раз xml-файл) // оптимизация (не загружаем второй раз xml-файл)
if( fname == uniset_conf()->getConfFileName() && confxml ) if( confxml && fname == confxml->getFileName() )
read( ic, confxml ); read(ic,confxml);
else if( uxml && uxml->isOpen() && uxml->filename == fn ) else if( uxml && uxml->isOpen() && uxml->getFileName() == fname )
read(ic,uxml); read(ic,uxml);
else else
{ {
......
...@@ -107,11 +107,17 @@ Configuration::~Configuration() ...@@ -107,11 +107,17 @@ Configuration::~Configuration()
delete[] _argv[i]; delete[] _argv[i];
delete[] _argv; delete[] _argv;
if( oind )
oind.reset();
if( unixml )
unixml.reset();
} }
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
Configuration::Configuration( int argc, const char* const* argv, const string& xmlfile ): Configuration::Configuration( int argc, const char* const* argv, const string& xmlfile ):
oind(NULL), oind(nullptr),
unixml(nullptr),
_argc(argc), _argc(argc),
_argv(argv), _argv(argv),
NSName("NameService"), NSName("NameService"),
...@@ -129,7 +135,8 @@ Configuration::Configuration( int argc, const char* const* argv, const string& x ...@@ -129,7 +135,8 @@ Configuration::Configuration( int argc, const char* const* argv, const string& x
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
Configuration::Configuration( int argc, const char* const* argv, shared_ptr<ObjectIndex> _oind, Configuration::Configuration( int argc, const char* const* argv, shared_ptr<ObjectIndex> _oind,
const string& fileConf ): const string& fileConf ):
oind(NULL), oind(nullptr),
unixml(nullptr),
_argc(argc), _argc(argc),
_argv(argv), _argv(argv),
NSName("NameService"), NSName("NameService"),
...@@ -198,7 +205,7 @@ void Configuration::initConfiguration( int argc, const char* const* argv ) ...@@ -198,7 +205,7 @@ void Configuration::initConfiguration( int argc, const char* const* argv )
try try
{ {
if( unixml == nullptr ) if( unixml == nullptr )
unixml = std::shared_ptr<UniXML>( new UniXML() ); unixml = make_shared<UniXML>();
if( !unixml->isOpen() ) if( !unixml->isOpen() )
{ {
...@@ -358,26 +365,23 @@ void Configuration::initConfiguration( int argc, const char* const* argv ) ...@@ -358,26 +365,23 @@ void Configuration::initConfiguration( int argc, const char* const* argv )
// create policy // create policy
CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj); PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
CORBA::PolicyList pl;
if( transientIOR == false ) if( transientIOR == false )
{ {
pl.length(3); policyList.length(3);
pl[0] = root_poa->create_lifespan_policy(PortableServer::PERSISTENT); policyList[0] = root_poa->create_lifespan_policy(PortableServer::PERSISTENT);
pl[1] = root_poa->create_id_assignment_policy(PortableServer::USER_ID); policyList[1] = root_poa->create_id_assignment_policy(PortableServer::USER_ID);
pl[2] = root_poa->create_request_processing_policy(PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY); policyList[2] = root_poa->create_request_processing_policy(PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY);
// pl[3] = root_poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL); // policyList[3] = root_poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL);
} }
else else
{ {
pl.length(3); policyList.length(3);
pl[0] = root_poa->create_lifespan_policy(PortableServer::TRANSIENT); policyList[0] = root_poa->create_lifespan_policy(PortableServer::TRANSIENT);
pl[1] = root_poa->create_servant_retention_policy(PortableServer::RETAIN); policyList[1] = root_poa->create_servant_retention_policy(PortableServer::RETAIN);
pl[2] = root_poa->create_request_processing_policy(PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY); policyList[2] = root_poa->create_request_processing_policy(PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY);
// pl[3] = root_poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL); // policyList[3] = root_poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL);
} }
policyList = pl;
// --------------------------------------- // ---------------------------------------
} }
......
...@@ -118,13 +118,16 @@ string UniXML::getPropUtf8(const xmlNode* node, const string& name) ...@@ -118,13 +118,16 @@ string UniXML::getPropUtf8(const xmlNode* node, const string& name)
string UniXML::getProp(const xmlNode* node, const string& name) string UniXML::getProp(const xmlNode* node, const string& name)
{ {
const char * text = (const char*)::xmlGetProp((xmlNode*)node, (const xmlChar*)name.c_str()); xmlChar* text = ::xmlGetProp((xmlNode*)node, (const xmlChar*)name.c_str());
if( text == NULL ) if( text == NULL )
{
xmlFree(text);
return ""; return "";
}
string t(text); const string t( (const char*)text );
xmlFree( (void*)text ); xmlFree(text);
return t; return std::move(t);
} }
int UniXML::getIntProp(const xmlNode* node, const string& name ) int UniXML::getIntProp(const xmlNode* node, const string& name )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment