From 17bac77e5b625018a086b66ed1cfd6ea8a592101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= <klinkjak@fjfi.cvut.cz> Date: Fri, 5 May 2017 18:28:42 +0200 Subject: [PATCH] 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. --- src/TNL/Object.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/TNL/Object.cpp b/src/TNL/Object.cpp index 14418d26da..74a4bbb7a1 100644 --- a/src/TNL/Object.cpp +++ b/src/TNL/Object.cpp @@ -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; return false; } - if( ! this->save( file ) ) - return false; + const bool status = this->save( file ); if( ! file. close() ) - { std::cerr << "An error occurred when I was closing the file " << fileName << "." << std::endl; - return false; - } - return true; + return status; } 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; return false; } - if( ! this->load( file ) ) - return false; + const bool status = this->load( file ); if( ! file. close() ) - { std::cerr << "An error occurred when I was closing the file " << fileName << "." << std::endl; - return false; - } - return true; + return status; } bool Object :: boundLoad( const String& fileName ) -- GitLab