control: forcemerge 695887 849763 882983
control: tags -1 patch

These bugs are caused by file descriptors not being closed properly. The
attached patch should help.
>From 1dbc071c3b966f4fb351948412ffe438de11e62f Mon Sep 17 00:00:00 2001
From: Nis Martensen <nis.marten...@web.de>
Date: Mon, 4 Dec 2017 21:33:15 +0100
Subject: [PATCH] Make sure some file descriptors will be closed properly

---
 bin/reportbug           |  3 ++-
 reportbug/submit.py     |  3 ++-
 reportbug/ui/text_ui.py | 18 ++++++++++--------
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/bin/reportbug b/bin/reportbug
index 7eda598..6a554b6 100755
--- a/bin/reportbug
+++ b/bin/reportbug
@@ -339,7 +339,8 @@ def handle_editing(filename, dmessage, options, sendto, attachments, package,
             skip_editing = True
             if x == 'l':
                 pager = os.environ.get('PAGER', 'sensible-pager')
-                os.popen(pager, 'w').write(message)
+                with os.popen(pager, 'w') as p:
+                    p.write(message)
             else:
                 sys.stdout.write(message)
         elif x == 't':
diff --git a/reportbug/submit.py b/reportbug/submit.py
index e6bd50b..ea613cb 100644
--- a/reportbug/submit.py
+++ b/reportbug/submit.py
@@ -265,7 +265,8 @@ def send_report(body, attachments, mua, fromaddr, sendto, ccaddr, bccaddr,
     if paranoid and not (template or printonly):
         pager = os.environ.get('PAGER', 'sensible-pager')
         try:
-            os.popen(pager, 'w').write(message)
+            with os.popen(pager, 'w') as p:
+                p.write(message)
         except  Exception as e:
             # if the PAGER exits before all the text has been sent,
             # it'd send a SIGPIPE, so crash only if that's not the case
diff --git a/reportbug/ui/text_ui.py b/reportbug/ui/text_ui.py
index b852b79..4a60ff8 100644
--- a/reportbug/ui/text_ui.py
+++ b/reportbug/ui/text_ui.py
@@ -451,10 +451,9 @@ def show_report(number, system, mirrors,
             text = 'Original report - %s\n\n%s' % (buginfo.subject, messages[0])
 
         if not skip_pager:
-            fd = os.popen('sensible-pager', 'w')
             try:
-                fd.write(text)
-                fd.close()
+                with os.popen('sensible-pager', 'w') as fd:
+                    fd.write(text)
             except IOError as x:
                 if x.errno == errno.EPIPE:
                     pass
@@ -1009,7 +1008,8 @@ def display_report(text, use_pager=True, presubj=False):
 
     pager = os.environ.get('PAGER', 'sensible-pager')
     try:
-        os.popen(pager, 'w').write(text)
+        with os.popen(pager, 'w') as p:
+            p.write(text)
     except IOError:
         pass
 
@@ -1023,9 +1023,10 @@ def spawn_editor(message, filename, editor, charset='utf-8'):
 
     # Move the cursor for lazy buggers like me; add your editor here...
     ourline = 0
-    for (lineno, line) in enumerate(open(filename)):
-        if line == '\n' and not ourline:
-            ourline = lineno + 2
+    with open(filename) as f:
+        for (lineno, line) in enumerate(f):
+            if line == '\n' and not ourline:
+                ourline = lineno + 2
 
     opts = ''
     if 'vim' in edname:
@@ -1061,7 +1062,8 @@ def spawn_editor(message, filename, editor, charset='utf-8'):
     if '&' in editor:
         return (None, 1)
 
-    newmessage = open(filename).read()
+    with open(filename) as f:
+        newmessage = f.read()
 
     if newmessage == message:
         ewrite('No changes were made in the editor.\n')
-- 
2.11.0

_______________________________________________
Reportbug-maint mailing list
Reportbug-maint@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/reportbug-maint

Reply via email to