diff options
author | Pierre-Marie de Rodat <derodat@adacore.com> | 2020-05-26 16:13:28 +0200 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2020-05-26 17:45:38 +0200 |
commit | bb07057a316f7f8c3daa1a4dd67fd3c5d9d450c7 (patch) | |
tree | f29fde9a9240e9ac011053ac7ed31358638754df | |
parent | 0981cf960d07752f9844a2f2799fbc85a7f1efd8 (diff) | |
download | gcc-bb07057a316f7f8c3daa1a4dd67fd3c5d9d450c7.zip gcc-bb07057a316f7f8c3daa1a4dd67fd3c5d9d450c7.tar.gz gcc-bb07057a316f7f8c3daa1a4dd67fd3c5d9d450c7.tar.bz2 |
gcc-changelog: remove file descriptor leaks
Currently, running gcc-changelog's unit tests may clutter the output
with tons of warnings such as:
.../contrib/gcc-changelog/git_email.py:40: ResourceWarning: unclosed
file <_io.TextIOWrapper name='/tmp/tmpt5okd4qp.patch' mode='r'
encoding='UTF-8'>
lines = open(self.filename).read().splitlines()
ResourceWarning: Enable tracemalloc to get the object allocation
traceback
This commit fixes these leaks, which restores a clean testsuite output.
contrib/
* gcc-changelog/git_update_version.py: Close file objects after
use.
* gcc-changelog/git_email.py: Likewise.
* gcc-changelog/test_email.py: Likewise.
-rwxr-xr-x | contrib/gcc-changelog/git_email.py | 3 | ||||
-rwxr-xr-x | contrib/gcc-changelog/git_update_version.py | 6 | ||||
-rwxr-xr-x | contrib/gcc-changelog/test_email.py | 3 |
3 files changed, 8 insertions, 4 deletions
diff --git a/contrib/gcc-changelog/git_email.py b/contrib/gcc-changelog/git_email.py index e1d6b70..8c9df29 100755 --- a/contrib/gcc-changelog/git_email.py +++ b/contrib/gcc-changelog/git_email.py @@ -37,7 +37,8 @@ class GitEmail(GitCommit): date = None author = None - lines = open(self.filename).read().splitlines() + with open(self.filename, 'r') as f: + lines = f.read().splitlines() lines = list(takewhile(lambda line: line != '---', lines)) for line in lines: if line.startswith(DATE_PREFIX): diff --git a/contrib/gcc-changelog/git_update_version.py b/contrib/gcc-changelog/git_update_version.py index 3dcc5625..6b6ccf6 100755 --- a/contrib/gcc-changelog/git_update_version.py +++ b/contrib/gcc-changelog/git_update_version.py @@ -28,7 +28,8 @@ current_timestamp = datetime.datetime.now().strftime('%Y%m%d\n') def read_timestamp(path): - return open(path).read() + with open(path) as f: + return f.read() def prepend_to_changelog_files(repo, folder, git_commit, add_to_git): @@ -40,7 +41,8 @@ def prepend_to_changelog_files(repo, folder, git_commit, add_to_git): full_path = os.path.join(folder, entry, 'ChangeLog') print('writting to %s' % full_path) if os.path.exists(full_path): - content = open(full_path).read() + with open(full_path) as f: + content = f.read() else: content = '' with open(full_path, 'w+') as f: diff --git a/contrib/gcc-changelog/test_email.py b/contrib/gcc-changelog/test_email.py index bf028a3..1379502e7 100755 --- a/contrib/gcc-changelog/test_email.py +++ b/contrib/gcc-changelog/test_email.py @@ -33,7 +33,8 @@ class TestGccChangelog(unittest.TestCase): filename = None patch_lines = [] - lines = open(os.path.join(script_path, 'test_patches.txt')).read() + with open(os.path.join(script_path, 'test_patches.txt')) as f: + lines = f.read() for line in lines.split('\n'): if line.startswith('==='): if patch_lines: |