Package: python2.4-minimal
Version:  2.4.4-3+etch1
Tags: patch

I'm observing a descriptor leak issue using python 2.4 as distributed in etch.
This is on an amd64 architecture system.

The following code leaks two file descriptors when 'jpegexiforient' is
not installed:

    try:
        get_orient = subprocess.Popen (['jpegexiforient', '-n', pathfull],
                                       stdin = subprocess.PIPE,
                                       stdout = subprocess.PIPE)
        orient = get_orient.communicate ()[0]
    except:
        orient = None

If executed in a loop, the process soon runs out of file descriptors.

Looking at the issue, I believe this will happen on any posix system when
subprocess.Popen is invoked with stdin or stdout equal to subprocess.PIPE
and the desired executable can't be executed.

The attached patch seems to solve the issue for me.

-- 
Michel "Walken" Lespinasse
A program is never fully debugged until the last user dies.
--- /usr/lib/python2.4/subprocess.py	2008-04-16 10:59:00.000000000 -0700
+++ subprocess.py	2008-08-28 13:09:50.000000000 -0700
@@ -970,6 +970,12 @@
             data = os.read(errpipe_read, 1048576) # Exceptions limited to 1 MB
             os.close(errpipe_read)
             if data != "":
+		if p2cwrite:
+		    os.close(p2cwrite)
+		if c2pread and c2pread not in (p2cwrite,):
+		    os.close(c2pread)
+		if errread and errread not in (p2cwrite, c2pread):
+		    os.close(errread)
                 os.waitpid(self.pid, 0)
                 child_exception = pickle.loads(data)
                 raise child_exception

Reply via email to