fg_io: Fixed mem leaks.
This commit is contained in:
parent
a704a62081
commit
5049ecce71
2 changed files with 39 additions and 36 deletions
|
@ -83,9 +83,6 @@ FGIO::FGIO()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FGIO::~FGIO()
|
FGIO::~FGIO()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -103,13 +100,13 @@ FGIO::parse_port_config( const string& config )
|
||||||
{
|
{
|
||||||
SG_LOG( SG_IO, SG_ALERT,
|
SG_LOG( SG_IO, SG_ALERT,
|
||||||
"Port configuration error: empty config string" );
|
"Port configuration error: empty config string" );
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
string protocol = tokens[0];
|
string protocol = tokens[0];
|
||||||
SG_LOG( SG_IO, SG_INFO, " protocol = " << protocol );
|
SG_LOG( SG_IO, SG_INFO, " protocol = " << protocol );
|
||||||
|
|
||||||
FGProtocol *io = 0;
|
FGProtocol *io = NULL;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -134,8 +131,6 @@ FGIO::parse_port_config( const string& config )
|
||||||
FGAtlas *atlas = new FGAtlas;
|
FGAtlas *atlas = new FGAtlas;
|
||||||
io = atlas;
|
io = atlas;
|
||||||
} else if ( protocol == "opengc" ) {
|
} else if ( protocol == "opengc" ) {
|
||||||
// char wait;
|
|
||||||
// printf("Parsed opengc\n"); cin >> wait;
|
|
||||||
FGOpenGC *opengc = new FGOpenGC;
|
FGOpenGC *opengc = new FGOpenGC;
|
||||||
io = opengc;
|
io = opengc;
|
||||||
} else if ( protocol == "AV400" ) {
|
} else if ( protocol == "AV400" ) {
|
||||||
|
@ -218,7 +213,7 @@ FGIO::parse_port_config( const string& config )
|
||||||
short port = atoi(tokens[4].c_str());
|
short port = atoi(tokens[4].c_str());
|
||||||
|
|
||||||
// multiplay used to be handled by an FGProtocol, but no longer. This code
|
// multiplay used to be handled by an FGProtocol, but no longer. This code
|
||||||
// retains compatability with existing command-line syntax
|
// retains compatibility with existing command-line syntax
|
||||||
fgSetInt("/sim/multiplay/tx-rate-hz", rate);
|
fgSetInt("/sim/multiplay/tx-rate-hz", rate);
|
||||||
if (dir == "in") {
|
if (dir == "in") {
|
||||||
fgSetInt("/sim/multiplay/rxport", port);
|
fgSetInt("/sim/multiplay/rxport", port);
|
||||||
|
@ -229,12 +224,12 @@ FGIO::parse_port_config( const string& config )
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
#ifdef FG_HAVE_HLA
|
|
||||||
} else if ( protocol == "hla" ) {
|
|
||||||
return new FGHLA(tokens);
|
|
||||||
}
|
}
|
||||||
|
#ifdef FG_HAVE_HLA
|
||||||
|
else if ( protocol == "hla" ) {
|
||||||
|
return new FGHLA(tokens);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
else {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,11 +237,12 @@ FGIO::parse_port_config( const string& config )
|
||||||
{
|
{
|
||||||
SG_LOG( SG_IO, SG_ALERT, "Port configuration error: " << err.what() );
|
SG_LOG( SG_IO, SG_ALERT, "Port configuration error: " << err.what() );
|
||||||
delete io;
|
delete io;
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tokens.size() < 3) {
|
if (tokens.size() < 3) {
|
||||||
SG_LOG( SG_IO, SG_ALERT, "Incompatible number of network arguments.");
|
SG_LOG( SG_IO, SG_ALERT, "Incompatible number of network arguments.");
|
||||||
|
delete io;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
string medium = tokens[1];
|
string medium = tokens[1];
|
||||||
|
@ -264,6 +260,7 @@ FGIO::parse_port_config( const string& config )
|
||||||
if ( medium == "serial" ) {
|
if ( medium == "serial" ) {
|
||||||
if ( tokens.size() < 5) {
|
if ( tokens.size() < 5) {
|
||||||
SG_LOG( SG_IO, SG_ALERT, "Incompatible number of arguments for serial communications.");
|
SG_LOG( SG_IO, SG_ALERT, "Incompatible number of arguments for serial communications.");
|
||||||
|
delete io;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
// device name
|
// device name
|
||||||
|
@ -281,6 +278,7 @@ FGIO::parse_port_config( const string& config )
|
||||||
if ( protocol == "AV400WSimB" ) {
|
if ( protocol == "AV400WSimB" ) {
|
||||||
if ( tokens.size() < 7 ) {
|
if ( tokens.size() < 7 ) {
|
||||||
SG_LOG( SG_IO, SG_ALERT, "Missing second hz for AV400WSimB.");
|
SG_LOG( SG_IO, SG_ALERT, "Missing second hz for AV400WSimB.");
|
||||||
|
delete io;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
FGAV400WSimB *fgavb = static_cast<FGAV400WSimB*>(io);
|
FGAV400WSimB *fgavb = static_cast<FGAV400WSimB*>(io);
|
||||||
|
@ -292,6 +290,7 @@ FGIO::parse_port_config( const string& config )
|
||||||
// file name
|
// file name
|
||||||
if ( tokens.size() < 4) {
|
if ( tokens.size() < 4) {
|
||||||
SG_LOG( SG_IO, SG_ALERT, "Incompatible number of arguments for file I/O.");
|
SG_LOG( SG_IO, SG_ALERT, "Incompatible number of arguments for file I/O.");
|
||||||
|
delete io;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,6 +312,7 @@ FGIO::parse_port_config( const string& config )
|
||||||
} else if ( medium == "socket" ) {
|
} else if ( medium == "socket" ) {
|
||||||
if ( tokens.size() < 6) {
|
if ( tokens.size() < 6) {
|
||||||
SG_LOG( SG_IO, SG_ALERT, "Incompatible number of arguments for socket communications.");
|
SG_LOG( SG_IO, SG_ALERT, "Incompatible number of arguments for socket communications.");
|
||||||
|
delete io;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
string hostname = tokens[4];
|
string hostname = tokens[4];
|
||||||
|
@ -340,31 +340,36 @@ FGIO::init()
|
||||||
|
|
||||||
_realDeltaTime = fgGetNode("/sim/time/delta-realtime-sec");
|
_realDeltaTime = fgGetNode("/sim/time/delta-realtime-sec");
|
||||||
|
|
||||||
FGProtocol *p;
|
|
||||||
|
|
||||||
// we could almost do this in a single step except pushing a valid
|
// we could almost do this in a single step except pushing a valid
|
||||||
// port onto the port list copies the structure and destroys the
|
// port onto the port list copies the structure and destroys the
|
||||||
// original, which closes the port and frees up the fd ... doh!!!
|
// original, which closes the port and frees up the fd ... doh!!!
|
||||||
|
|
||||||
// parse the configuration strings and store the results in the
|
|
||||||
// appropriate FGIOChannel structures
|
|
||||||
string_list::iterator i = globals->get_channel_options_list()->begin();
|
string_list::iterator i = globals->get_channel_options_list()->begin();
|
||||||
string_list::iterator end = globals->get_channel_options_list()->end();
|
string_list::iterator end = globals->get_channel_options_list()->end();
|
||||||
for (; i != end; ++i ) {
|
for (; i != end; ++i ) {
|
||||||
p = parse_port_config( *i );
|
add_channel( *i );
|
||||||
if (!p) {
|
} // of channel options iteration
|
||||||
continue;
|
}
|
||||||
|
|
||||||
|
// add another I/O channel
|
||||||
|
void FGIO::add_channel(const string& config)
|
||||||
|
{
|
||||||
|
// parse the configuration string and store the results in the
|
||||||
|
// appropriate FGIOChannel structure
|
||||||
|
FGProtocol *p = parse_port_config( config );
|
||||||
|
if (!p)
|
||||||
|
{
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
p->open();
|
p->open();
|
||||||
if ( !p->is_enabled() ) {
|
if ( !p->is_enabled() ) {
|
||||||
SG_LOG( SG_IO, SG_ALERT, "I/O Channel config failed." );
|
SG_LOG( SG_IO, SG_ALERT, "I/O Channel config failed." );
|
||||||
delete p;
|
delete p;
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
io_channels.push_back( p );
|
io_channels.push_back( p );
|
||||||
} // of channel options iteration
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -408,13 +413,11 @@ FGIO::update( double /* delta_time_sec */ )
|
||||||
void
|
void
|
||||||
FGIO::shutdown()
|
FGIO::shutdown()
|
||||||
{
|
{
|
||||||
FGProtocol *p;
|
|
||||||
|
|
||||||
ProtocolVec::iterator i = io_channels.begin();
|
ProtocolVec::iterator i = io_channels.begin();
|
||||||
ProtocolVec::iterator end = io_channels.end();
|
ProtocolVec::iterator end = io_channels.end();
|
||||||
for (; i != end; ++i )
|
for (; i != end; ++i )
|
||||||
{
|
{
|
||||||
p = *i;
|
FGProtocol *p = *i;
|
||||||
if ( p->is_enabled() ) {
|
if ( p->is_enabled() ) {
|
||||||
p->close();
|
p->close();
|
||||||
}
|
}
|
||||||
|
@ -434,4 +437,3 @@ void
|
||||||
FGIO::unbind()
|
FGIO::unbind()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// fg_io.hxx -- Higher level I/O managment routines
|
// fg_io.hxx -- Higher level I/O management routines
|
||||||
//
|
//
|
||||||
// Written by Curtis Olson, started November 1999.
|
// Written by Curtis Olson, started November 1999.
|
||||||
//
|
//
|
||||||
|
@ -50,6 +50,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void add_channel(const std::string& config);
|
||||||
FGProtocol* parse_port_config( const std::string& cfgstr );
|
FGProtocol* parse_port_config( const std::string& cfgstr );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Reference in a new issue