Commit 71691352 authored by Pavel Vainerman's avatar Pavel Vainerman

Корректировка по результатам прогона valgrind

и мелкие исправления форматирования
parent 4bd9e8d9
......@@ -44,7 +44,6 @@ opCheckPause(50)
SQLiteInterface::~SQLiteInterface()
{
close();
delete db;
}
// -----------------------------------------------------------------------------------------
......@@ -261,7 +260,7 @@ SQLiteResult::SQLiteResult( sqlite3_stmt* s, bool finalize )
COL c;
for( unsigned int i=0; i<n; i++ )
for( int i=0; i<n; i++ )
{
char* p = (char*)sqlite3_column_text(s,i);
if( p )
......
......@@ -236,7 +236,7 @@ TEST_CASE("[UNetUDP]: check receiver","[unetudp][receiver]")
REQUIRE( ui->getValue(10) == 1 );
REQUIRE( ui->getValue(11) == 0 );
msleep(1000);
msleep(1500);
REQUIRE( ui->getValue(node2_respond_s) == 1 );
}
SECTION("Test: send data pack2..")
......@@ -253,7 +253,7 @@ TEST_CASE("[UNetUDP]: check receiver","[unetudp][receiver]")
REQUIRE( ui->getValue(10) == 0 );
REQUIRE( ui->getValue(11) == 1 );
REQUIRE( ui->getValue(node2_respond_s) == 1 );
msleep(3000); // в запускающем файле стоит --unet-recv-timeout 2000
msleep(2000); // в запускающем файле стоит --unet-recv-timeout 2000
REQUIRE( ui->getValue(node2_respond_s) == 0 );
}
}
......
......@@ -25,6 +25,7 @@ struct IOBase
IOBase( IOBase&& r ) = default;
IOBase& operator=(IOBase&& r) = default;
~IOBase();
IOBase():
stype(UniversalIO::UnknownIOType),
cdiagram(nullptr),
......
#include "Configuration.h"
#include "Extensions.h"
#include "IOBase.h"
......@@ -11,6 +12,11 @@ std::ostream& operator<<( std::ostream& os, IOBase& inf )
<< " default=" << inf.defval << " safety=" << inf.safety;
}
// -----------------------------------------------------------------------------
IOBase::~IOBase()
{
delete cdiagram;
}
// -----------------------------------------------------------------------------
bool IOBase::check_channel_break( long val )
{
// порог не задан... (проверка отключена)
......
......@@ -62,4 +62,6 @@ TEST_CASE("Calibration","[calibration]")
REQUIRE( cal->getLeftRaw() == -1000 );
REQUIRE( cal->getRightRaw() == 1000 );
}
delete cal;
}
......@@ -154,6 +154,8 @@ namespace UniSetTypes
return uni_atoi(str.c_str());
}
char* uni_strdup( const std::string& src );
std::string timeToString(time_t tm=time(0), const std::string& brk=":"); /*!< Преобразование времени в строку HH:MM:SS */
std::string dateToString(time_t tm=time(0), const std::string& brk="/"); /*!< Преобразование даты в строку DD/MM/YYYY */
......
......@@ -76,8 +76,8 @@ namespace ORepHelpers
CosNaming::NamingContext_var ctx;
try
{
CORBA::Object_var o = rootC->resolve(ctxName);
ctx = CosNaming::NamingContext::_narrow(o);
CORBA::Object_var o = rootC->resolve( ctxName.in() );
ctx = CosNaming::NamingContext::_narrow(o.in());
if( CORBA::is_nil(ctx) )
{
const string err("OREPHELPER(getContext): не смог получить ссылку на контекст(is_nil) "+cname);
......
......@@ -48,6 +48,11 @@ omap(minSize)
// -----------------------------------------------------------------------------------------
ObjectIndex_XML::~ObjectIndex_XML()
{
for( auto& it: omap )
{
delete[] it.repName;
delete[] it.textName;
}
}
// -----------------------------------------------------------------------------------------
ObjectId ObjectIndex_XML::getIdByName( const string& name )
......@@ -173,7 +178,9 @@ unsigned int ObjectIndex_XML::read_section( const std::shared_ptr<UniXML>& xml,
omap[ind].id = ind;
// name
const string name(secname + xml->getProp(it,"name"));
ostringstream n;
n << secname << xml->getProp(it,"name");
const string name(n.str());
delete[] omap[ind].repName;
omap[ind].repName = new char[name.size()+1];
strcpy( omap[ind].repName, name.c_str() );
......
......@@ -26,6 +26,11 @@ ObjectIndex_idXML::ObjectIndex_idXML( const shared_ptr<UniXML>& xml )
// -----------------------------------------------------------------------------------------
ObjectIndex_idXML::~ObjectIndex_idXML()
{
for( auto& it: omap )
{
delete[] it.second.repName;
delete[] it.second.textName;
}
}
// -----------------------------------------------------------------------------------------
ObjectId ObjectIndex_idXML::getIdByName( const string& name )
......@@ -142,7 +147,9 @@ void ObjectIndex_idXML::read_section( const std::shared_ptr<UniXML>& xml, const
}
// name
string name( secname+it.getProp("name") );
ostringstream n;
n << secname << it.getProp("name");
string name(n.str());
inf.repName = new char[name.size()+1];
strcpy( inf.repName, name.c_str() );
......
......@@ -401,3 +401,12 @@ int UniSetTypes::uni_atoi( const char* str )
return n;
}
//--------------------------------------------------------------------------------------------
char* UniSetTypes::uni_strdup( const string& src )
{
const char* s = src.c_str();
size_t len = strlen(s);
char* d = new char[len+1];
memcpy(d,s,len+1);
return d;
}
// -------------------------------------------------------------------------
......@@ -70,7 +70,7 @@ uxml(0)
// ------------------------------------------------------------------------------------------
NCRestorer_XML::~NCRestorer_XML()
{
if( uxml)
if( uxml )
{
uxml->close();
uxml.reset();
......
......@@ -71,8 +71,6 @@ ostream& UniSetTypes::Configuration::help(ostream& os)
<< "--ulog-add-levels level1,info,system,warn --ulog-log-in-file myprogrpam.log\n\n";
}
// -------------------------------------------------------------------------
namespace UniSetTypes
{
DebugStream ulog;
......@@ -105,6 +103,10 @@ Configuration::Configuration():
Configuration::~Configuration()
{
for( int i=0; i<_argc; i++ )
delete[] _argv[i];
delete[] _argv;
}
// ---------------------------------------------------------------------------------
......@@ -258,8 +260,6 @@ void Configuration::initConfiguration( int argc, const char* const* argv )
setLocalNode(lnode);
initParameters();
initRepSections();
// localIOR
......@@ -290,7 +290,7 @@ void Configuration::initConfiguration( int argc, const char* const* argv )
int i = 0;
// перегоняем старые параметры
for( ; i < argc; i++ )
new_argv[i] = strdup(argv[i]);
new_argv[i] = uni_strdup(argv[i]);
// формируем новые, используя i в качестве индекса
for( auto &it: lnodes )
......@@ -302,9 +302,10 @@ void Configuration::initConfiguration( int argc, const char* const* argv )
param << this << name;
name = param.str();
param << "=corbaname::" << it.host << ":" << it.port;
new_argv[i+1] = strdup(param.str().c_str());
const string sparam(param.str());
new_argv[i+1] = uni_strdup(sparam);
uinfo << "(Configuration): внесли параметр " << param.str() << endl;
uinfo << "(Configuration): внесли параметр " << sparam << endl;
i+=2;
ostringstream uri;
......@@ -336,8 +337,9 @@ void Configuration::initConfiguration( int argc, const char* const* argv )
ostringstream param;
param << this << "NameService=corbaname::" << getProp(nsnode,"host") << ":" << defPort;
new_argv[i+1] = strdup(param.str().c_str());
uinfo << "(Configuration): внесли параметр " << param.str() << endl;
const string sparam(param.str());
new_argv[i+1] = uni_strdup(sparam);
uinfo << "(Configuration): внесли параметр " << sparam << endl;
{
ostringstream ns_name;
......@@ -345,7 +347,7 @@ void Configuration::initConfiguration( int argc, const char* const* argv )
ostringstream uri;
uri << "corbaname::" << getProp(nsnode,"host") << ":" << defPort;
if( !omni::omniInitialReferences::setFromArgs(ns_name.str().c_str(), uri.str().c_str()) )
cerr << "**********************!!!! FAILED ADD name=" <<ns_name << " uri=" << uri.str() << endl;
cerr << "**********************!!!! FAILED ADD name=" << ns_name << " uri=" << uri.str() << endl;
}
}
......@@ -772,6 +774,13 @@ xmlNode* Configuration::initDebug( DebugStream& deb, const string& _debname )
return dnode;
}
// -------------------------------------------------------------------------
static std::string makeSecName( const std::string& sec, const std::string& name )
{
ostringstream n;
n << sec << "/" << name;
return std::move(n.str());
}
// -------------------------------------------------------------------------
void Configuration::initRepSections()
{
// Реализация под жёсткую структуру репозитория
......@@ -785,12 +794,12 @@ void Configuration::initRepSections()
}
secRoot = unixml->getProp(node,"name");
secSensors = secRoot + "/" + getRepSectionName("sensors",xmlSensorsSec);
secObjects = secRoot + "/" + getRepSectionName("objects",xmlObjectsSec);
secControlles = secRoot + "/" + getRepSectionName("controllers",xmlControllersSec);
secServices = secRoot + "/" + getRepSectionName("services",xmlServicesSec);
secSensors = makeSecName(secRoot, getRepSectionName("sensors",xmlSensorsSec));
secObjects = makeSecName(secRoot, getRepSectionName("objects",xmlObjectsSec));
secControlles = makeSecName(secRoot, getRepSectionName("controllers",xmlControllersSec));
secServices = makeSecName(secRoot, getRepSectionName("services",xmlServicesSec));
}
// -------------------------------------------------------------------------
string Configuration::getRepSectionName( const string& sec, xmlNode* secnode )
{
xmlNode* node = unixml->findNode(unixml->getFirstNode(),sec);
......@@ -808,7 +817,7 @@ string Configuration::getRepSectionName( const string& sec, xmlNode* secnode )
if( ret.empty() )
ret = unixml->getProp(node,"name");
return ret;
return std::move(ret);
}
// -------------------------------------------------------------------------
void Configuration::setConfFileName( const string& fn )
......
......@@ -43,34 +43,34 @@ TEST_CASE("CallbackTimer", "[CallbackTimer]" )
tmr.run();
msleep(60);
REQUIRE( tc.getNum1() == 1 );
REQUIRE( tc.getNum1() >= 1 );
REQUIRE( tc.getNum2() == 0 );
REQUIRE( tc.getNum3() == 0 );
msleep(110);
REQUIRE( tc.getNum1() == 3 );
REQUIRE( tc.getNum2() == 1 );
REQUIRE( tc.getNum1() >= 3 );
REQUIRE( tc.getNum2() >= 1 );
REQUIRE( tc.getNum3() == 0 );
msleep(210);
REQUIRE( tc.getNum1() == 7 );
REQUIRE( tc.getNum2() == 2 );
REQUIRE( tc.getNum1() >= 7 );
REQUIRE( tc.getNum2() >= 2 );
REQUIRE( tc.getNum3() == 1 );
tmr.remove(1);
msleep(60);
REQUIRE( tc.getNum1() == 7 );
REQUIRE( tc.getNum1() >= 7 );
tmr.terminate();
REQUIRE( tc.getNum2() == 2 );
REQUIRE( tc.getNum3() == 1 );
REQUIRE( tc.getNum2() >= 2 );
REQUIRE( tc.getNum3() >= 1 );
}
SECTION("other tests")
{
MyTestClass tc;
CallbackTimer<MyTestClass> tmr(&tc,&MyTestClass::Time);
int i=0;
unsigned int i = 0;
for( ;i<tmr.MAXCallbackTimer; i++ )
tmr.add(i,100 );
......
#include <catch.hpp>
// -----------------------------------------------------------------------------
#include <sstream>
#include <limits>
#include "UniSetTypes.h"
// -----------------------------------------------------------------------------
using namespace std;
using namespace UniSetTypes;
// -----------------------------------------------------------------------------
TEST_CASE("UniSetTypes: uni_atoi", "[utypes][uni_atoi]" )
{
SECTION("int")
......@@ -52,4 +53,24 @@ TEST_CASE("UniSetTypes: uni_atoi", "[utypes][uni_atoi]" )
WARN("Tests for 'UniSetTypes' incomplete...");
}
// -----------------------------------------------------------------------------
TEST_CASE("UniSetTypes: uni_strdup", "[utypes][uni_strdup]" )
{
SECTION("uni_strdup string")
{
string str("Test string");
const char* cp = uni_strdup(str);
string str2(cp);
REQUIRE( str == str2 );
delete[] cp;
}
SECTION("uni_strdup char*")
{
const char* str = "Test string";
char* str2 = uni_strdup(str);
REQUIRE( !strcmp(str,str2) );
delete[] str2;
}
}
// -----------------------------------------------------------------------------
{
sed
Memcheck:Leak
...
obj:/bin/sed
}
{
ps
Memcheck:Leak
...
obj:/bin/ps
}
{
bash
Memcheck:Leak
match-leak-kinds: definite
fun:malloc
fun:xmalloc
fun:make_if_command
fun:yyparse
fun:parse_command
fun:read_command
fun:reader_loop
}
{
omniORB
Memcheck:Leak
...
obj:/usr/lib/libomniORB4.so.*
}
{
omniNames
Memcheck:Leak
...
obj:/usr/bin/omniNames
}
{
libxml2
Memcheck:Leak
...
obj:/usr/lib/libxml2.so.*
}
#{
# libstdc++
# Memcheck:Leak
# ...
# /usr/lib/libstdc++.so.*
#}
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