From 462fad4cea04bee25aeae56ecb34c2ce799cc28d Mon Sep 17 00:00:00 2001 From: rnv Date: Mon, 5 May 2014 19:35:24 +0400 Subject: [PATCH 1/1] Fix a problem with the zero file descriptor. --- src/SMESHUtils/SMESH_File.cxx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/SMESHUtils/SMESH_File.cxx b/src/SMESHUtils/SMESH_File.cxx index b07205516..d4311bb71 100644 --- a/src/SMESHUtils/SMESH_File.cxx +++ b/src/SMESHUtils/SMESH_File.cxx @@ -45,7 +45,13 @@ namespace boofs = boost::filesystem; //================================================================================ SMESH_File::SMESH_File(const std::string& name, bool open) - :_name(name), _size(-1), _file(0), _map(0), _pos(0), _end(0) + :_name(name), _size(-1), +#ifdef WIN32 + _file(INVALID_HANDLE_VALUE), +#else + _file(-1), +#endif + _map(0), _pos(0), _end(0) { if ( open ) this->open(); } @@ -138,11 +144,15 @@ void SMESH_File::close() else if ( _file >= 0 ) { #ifdef WIN32 - CloseHandle(_file); - _file = INVALID_HANDLE_VALUE; + if(_file != INVALID_HANDLE_VALUE) { + CloseHandle(_file); + _file = INVALID_HANDLE_VALUE; + } #else - ::close(_file); - _file = -1; + if(_file != -1) { + ::close(_file); + _file = -1; + } #endif } } -- 2.30.2