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‎

Lines changed: 5 additions & 0 deletions
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+
ifproc.stdin:
386+
proc.stdin.close()
387+
proc.poll()
388+
ifproc.returncodeisNone:
389+
proc.terminate()
385390

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

‎git/objects/commit.py‎

Lines changed: 21 additions & 14 deletions
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
ifnothasattr(stream,'readline'):
354355
stream=proc_or_stream.stdout
356+
close_std_err=True
355357

356358
readline=stream.readline
357-
whileTrue:
358-
line=readline()
359-
ifnotline:
360-
break
361-
hexsha=line.strip()
362-
iflen(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-
assertlen(hexsha) ==40, "Invalid line: %s"%hexsha
368-
yieldcls(odb, hex_to_bin(hexsha))
369-
# END for each line in stream
370-
359+
try:
360+
whileTrue:
361+
line=readline()
362+
ifnotline:
363+
break
364+
hexsha=line.strip()
365+
iflen(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+
assertlen(hexsha) ==40, "Invalid line: %s"%hexsha
371+
yieldcls(odb, hex_to_bin(hexsha))
372+
# END for each line in stream
373+
finally:
374+
stream.close()
375+
ifclose_std_err:
376+
proc_or_stream.stderr.close()
377+
371378
#{Serializable Implementation
372379

373380
def_serialize(self, stream):

0 commit comments

Comments
(0)