don't leak file handle

This commit is contained in:
Axel Kohlmeyer
2024-08-02 17:41:13 -04:00
parent a905c9fd32
commit d3919be102

View File

@ -763,11 +763,12 @@ void FixQEq::read_file(char *file)
chi[n] = eta[n] = gamma[n] = zeta[n] = zcore[n] = 0.0; chi[n] = eta[n] = gamma[n] = zeta[n] = zcore[n] = 0.0;
} }
FILE *fp = nullptr;
try { try {
int nlo,nhi; int nlo,nhi;
double val; double val;
FILE *fp = utils::open_potential(file,lmp,nullptr); fp = utils::open_potential(file,lmp,nullptr);
if (fp == nullptr) if (fp == nullptr)
throw qeq_parser_error(fmt::format("Cannot open fix qeq parameter file {}: {}", throw qeq_parser_error(fmt::format("Cannot open fix qeq parameter file {}: {}",
file,utils::getsyserror())); file,utils::getsyserror()));
@ -798,7 +799,7 @@ void FixQEq::read_file(char *file)
for (int n=nlo; n <= nhi; ++n) setflag[n] = 1; for (int n=nlo; n <= nhi; ++n) setflag[n] = 1;
} }
} catch (EOFException &) { } catch (EOFException &) {
; // catch and ignore to exit loop fclose(fp);
} catch (std::exception &e) { } catch (std::exception &e) {
error->one(FLERR,e.what()); error->one(FLERR,e.what());
} }