diff --git a/src/ACGL/Base/FileOperations.cc b/src/ACGL/Base/FileOperations.cc index c041fbd90aaf8893fdfe1f53843aa532115aab2b..c138f4331e3dd4f33272c466c589febdd592a3dc 100644 --- a/src/ACGL/Base/FileOperations.cc +++ b/src/ACGL/Base/FileOperations.cc @@ -30,11 +30,15 @@ bool FileOperations::rawData(const std::string& _filename, char*& _pData, long_t _size = ftell(pFile); rewind(pFile); - // allocate memory to contain the whole file: - _pData = new char[sizeof(char)*_size]; - if(_pData == NULL) + try + { + // allocate memory to contain the whole file: + _pData = new char[_size]; + } + catch(...) { error() << "Memory error!" << std::endl; + fclose (pFile); return false; } @@ -43,6 +47,7 @@ bool FileOperations::rawData(const std::string& _filename, char*& _pData, long_t if ( (long_t)result != _size) { error() << "Reading error!" << std::endl; + fclose (pFile); return false; }