msv-lab / angelix

Semantic program repair system for C programs

Home Page:http://angelix.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Files are never closed after being written (in src/repair)

MinxingTang opened this issue · comments

This issue exists in almost all python code in src/repair. Every time a "file.write()" is invoked, a corresponding "file.close()" is forgotten.
Here is an example from src/repair/transformation.py of class FixInjector:

        patch_file = join(dirpath, 'patch')
        with open(patch_file, 'w') as file:
            for e, p in patch.items():
                file.write('{} {} {} {}\n'.format(*e))
                file.write(p + "\n")

The "file" is not closed after being written.
I think it would also be better to add an exception handler for file writing.

@MinxingTang I didn't look into the source code deeply, but in your example, the file is closed after all the writes when the control flows out of the with block. See https://docs.python.org/3/reference/compound_stmts.html#index-16 .

@yxliang01 Aha, I see. Then it shouldn't be any issue there. This issue can be closed, since others are using "with" blocks too.