diff hgext/patchbomb.py @ 52566:2bf9458cede3

patchbomb: don't leak a file descriptor when handling the description message Two possible leaks here, plus I bungled aa31c8566fb8 trying to read the file in binary mode, and instead gave the `rb` arg meant for `open()` as a second arg to `get()`. Instead, use the `util` function for readability.
author Matt Harbison <matt_harbison@yahoo.com>
date Mon, 16 Dec 2024 20:52:20 -0500
parents aa31c8566fb8
children
line wrap: on
line diff
--- a/hgext/patchbomb.py	Mon Dec 16 20:45:49 2024 -0500
+++ b/hgext/patchbomb.py	Mon Dec 16 20:52:20 2024 -0500
@@ -409,7 +409,7 @@
     """
     ui = repo.ui
     if opts.get('desc'):
-        body = open(opts.get('desc', 'rb')).read()
+        body = util.readfile(opts.get('desc'))
     else:
         ui.write(
             _(b'\nWrite the introductory message for the patch series.\n\n')
@@ -417,10 +417,11 @@
         body = ui.edit(
             defaultbody, sender, repopath=repo.path, action=b'patchbombbody'
         )
+
         # Save series description in case sendmail fails
-        msgfile = repo.vfs(b'last-email.txt', b'wb')
-        msgfile.write(body)
-        msgfile.close()
+        with repo.vfs(b'last-email.txt', b'wb') as msgfile:
+            msgfile.write(body)
+
     return body