Skip to content

Commit edb0587

Browse files
committed
Fixed a missing fclose
(to be backported as a fix)
1 parent f5110df commit edb0587

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/mapping/PathTools.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,11 @@ int PathTools::main(FILE* in, FILE*out,Communicator& pc) {
144144
std::string ofmt; parse("--arg-fmt",ofmt);
145145
std::string ofilename; parse("--out",ofilename);
146146
if( ifilename.length()>0 ) {
147-
fprintf(out,"Reparameterising path in file named %s so that all frames are equally spaced \n",ifilename.c_str() );
148-
FILE* fp=fopen(ifilename.c_str(),"r");
147+
std::fprintf(out,"Reparameterising path in file named %s so that all frames are equally spaced \n",ifilename.c_str() );
148+
FILE* fp=std::fopen(ifilename.c_str(),"r");
149+
// call fclose when fp goes out of scope
150+
auto deleter=[](FILE* f) { if(f) std::fclose(f); };
151+
std::unique_ptr<FILE,decltype(deleter)> fp_deleter(fp,deleter);
149152
bool do_read=true; std::vector<std::unique_ptr<ReferenceConfiguration>> frames;
150153
while (do_read) {
151154
PDB mypdb;

0 commit comments

Comments
 (0)