Skip to content

Commit d68ffc3

Browse files
committed
Closing file handles/streams
1 parent ad715a0 commit d68ffc3

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

‎git/cmd.py

+5
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@ def execute(self, command,
382382
finally:
383383
proc.stdout.close()
384384
proc.stderr.close()
385+
if proc.stdin:
386+
proc.stdin.close()
387+
proc.poll()
388+
if proc.returncode is None:
389+
proc.terminate()
385390

386391
if self.GIT_PYTHON_TRACE == 'full':
387392
cmdstr = " ".join(command)

‎git/objects/commit.py

+21-14
Original file line numberDiff line numberDiff line change
@@ -350,24 +350,31 @@ def _iter_from_process_or_stream(cls, odb, proc_or_stream):
350350
:param proc: git-rev-list process instance - one sha per line
351351
:return: iterator returning Commit objects"""
352352
stream = proc_or_stream
353+
close_std_err = False
353354
if not hasattr(stream,'readline'):
354355
stream = proc_or_stream.stdout
356+
close_std_err = True
355357

356358
readline = stream.readline
357-
while True:
358-
line = readline()
359-
if not line:
360-
break
361-
hexsha = line.strip()
362-
if len(hexsha) > 40:
363-
# split additional information, as returned by bisect for instance
364-
hexsha, rest = line.split(None, 1)
365-
# END handle extra info
366-
367-
assert len(hexsha) == 40, "Invalid line: %s" % hexsha
368-
yield cls(odb, hex_to_bin(hexsha))
369-
# END for each line in stream
370-
359+
try:
360+
while True:
361+
line = readline()
362+
if not line:
363+
break
364+
hexsha = line.strip()
365+
if len(hexsha) > 40:
366+
# split additional information, as returned by bisect for instance
367+
hexsha, rest = line.split(None, 1)
368+
# END handle extra info
369+
370+
assert len(hexsha) == 40, "Invalid line: %s" % hexsha
371+
yield cls(odb, hex_to_bin(hexsha))
372+
# END for each line in stream
373+
finally:
374+
stream.close()
375+
if close_std_err:
376+
proc_or_stream.stderr.close()
377+
371378
#{ Serializable Implementation
372379

373380
def _serialize(self, stream):

0 commit comments

Comments
 (0)