# HG changeset patch # User Matt Harbison # Date 1734400340 18000 # Node ID 2bf9458cede36cf78e1270f780614efc55abc36f # Parent d3d1fd3b8a9d1ffc19d776f0078c595124cd1b47 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. diff -r d3d1fd3b8a9d -r 2bf9458cede3 hgext/patchbomb.py --- 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