From cb68f36c9a2cd18a38e2b2c4630fd2131bfa3879 Mon Sep 17 00:00:00 2001 From: Tatsuki Sugiura Date: Tue, 8 May 2012 09:18:36 +0900 Subject: [PATCH 1/2] Fix fd leak on git cmd. Currently if command is called with as_proces=True, pipes for the command will not be closed. This change makes sure to close command file descriptors. --- git/cmd.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/git/cmd.py b/git/cmd.py index 576a5300a..385c9fff3 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -73,6 +73,9 @@ def __init__(self, proc, args ): self.args = args def __del__(self): + self.proc.stdout.close() + self.proc.stderr.close() + # did the process finish already so we have a return code ? if self.proc.poll() is not None: return @@ -100,6 +103,8 @@ def wait(self): :raise GitCommandError: if the return status is not 0""" status = self.proc.wait() + self.proc.stdout.close() + self.proc.stderr.close() if status != 0: raise GitCommandError(self.args, status, self.proc.stderr.read()) # END status handling From f467834059bb1297df97df4e03149cd2b48b81e3 Mon Sep 17 00:00:00 2001 From: Tatsuki Sugiura Date: Tue, 8 May 2012 09:35:33 +0900 Subject: [PATCH 2/2] Ignore signal exception on AutoInterrupt destructor. When command run as subprocess, AutoInterrupt will kill the process on destructor. However, if process already finished, it raise OSError exception. This fix just ignore OSError on os.kill. --- git/cmd.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/git/cmd.py b/git/cmd.py index 385c9fff3..0cd3e86cc 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -87,6 +87,8 @@ def __del__(self): # try to kill it try: os.kill(self.proc.pid, 2) # interrupt signal + except OSError: + pass # ignore error when process already died except AttributeError: # try windows # for some reason, providing None for stdout/stderr still prints something. This is why