From 487a598d29d7dfee2511cc002c76ab4577a56b25 Mon Sep 17 00:00:00 2001 From: Joseph Fox-Rabinovitz Date: Tue, 5 Jan 2021 16:02:52 -0600 Subject: [PATCH] Fixed resource leak in HelloWorld plugin? --- manual/plugin_examples/helloworld/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/manual/plugin_examples/helloworld/__init__.py b/manual/plugin_examples/helloworld/__init__.py index c075e106ad..1004f0cb56 100644 --- a/manual/plugin_examples/helloworld/__init__.py +++ b/manual/plugin_examples/helloworld/__init__.py @@ -22,11 +22,11 @@ class HelloWorld(FileTypePlugin): def run(self, path_to_ebook): from calibre.ebooks.metadata.meta import get_metadata, set_metadata - file = open(path_to_ebook, 'r+b') - ext = os.path.splitext(path_to_ebook)[-1][1:].lower() - mi = get_metadata(file, ext) - mi.publisher = 'Hello World' - set_metadata(file, mi, ext) + with open(path_to_ebook, 'r+b') as file: + ext = os.path.splitext(path_to_ebook)[-1][1:].lower() + mi = get_metadata(file, ext) + mi.publisher = 'Hello World' + set_metadata(file, mi, ext) return path_to_ebook