Skip to content
Snippets Groups Projects
Commit 17bac77e authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Fixed memory leaks in Object

I was running a load method on some object in a loop, which was
returning false most of the time, and eventually the process run out of
file descriptors because the file was not closed properly.
parent 270c7797
No related branches found
No related tags found
No related merge requests found
...@@ -85,14 +85,10 @@ bool Object :: save( const String& fileName ) const ...@@ -85,14 +85,10 @@ bool Object :: save( const String& fileName ) const
std::cerr << "I am not bale to open the file " << fileName << " for writing." << std::endl; std::cerr << "I am not bale to open the file " << fileName << " for writing." << std::endl;
return false; return false;
} }
if( ! this->save( file ) ) const bool status = this->save( file );
return false;
if( ! file. close() ) if( ! file. close() )
{
std::cerr << "An error occurred when I was closing the file " << fileName << "." << std::endl; std::cerr << "An error occurred when I was closing the file " << fileName << "." << std::endl;
return false; return status;
}
return true;
} }
bool Object :: load( const String& fileName ) bool Object :: load( const String& fileName )
...@@ -103,14 +99,10 @@ bool Object :: load( const String& fileName ) ...@@ -103,14 +99,10 @@ bool Object :: load( const String& fileName )
std::cerr << "I am not bale to open the file " << fileName << " for reading." << std::endl; std::cerr << "I am not bale to open the file " << fileName << " for reading." << std::endl;
return false; return false;
} }
if( ! this->load( file ) ) const bool status = this->load( file );
return false;
if( ! file. close() ) if( ! file. close() )
{
std::cerr << "An error occurred when I was closing the file " << fileName << "." << std::endl; std::cerr << "An error occurred when I was closing the file " << fileName << "." << std::endl;
return false; return status;
}
return true;
} }
bool Object :: boundLoad( const String& fileName ) bool Object :: boundLoad( const String& fileName )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment