Skip to content

Commit d3fbd81

Browse files
committed
Merge pull request #25 from blackducksoftware/fix_file_descriptor_leak
Fix for file descriptor leaks
2 parents 2cd5061 + 581e6f2 commit d3fbd81

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

lib/ohloh_scm/adapters/bzrlib/bzrlib_pipe_client.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def initialize(repository_url)
66
@repository_url = repository_url
77
@py_script = File.dirname(__FILE__) + '/bzrlib_pipe_server.py'
88
end
9-
9+
1010
def start
1111
@pid, @stdin, @stdout, @stderr = POSIX::Spawn::popen4 "python #{@py_script}"
1212
open_repository
@@ -27,8 +27,9 @@ def send_command(cmd)
2727
# send the command
2828
@stdin.puts cmd
2929
@stdin.flush
30+
return if cmd == "QUIT"
3031

31-
# get status on stderr, first letter indicates state,
32+
# get status on stderr, first letter indicates state,
3233
# remaing value indicates length of the file content
3334
status = @stderr.read(10)
3435
flag = status[0,1]
@@ -46,6 +47,7 @@ def send_command(cmd)
4647

4748
def shutdown
4849
send_command("QUIT")
50+
[@stdout, @stdin, @stderr].each { |io| io.close unless io.closed? }
4951
Process.waitpid(@pid, Process::WNOHANG)
5052
end
5153
end

lib/ohloh_scm/adapters/bzrlib_adapter.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ module OhlohScm::Adapters
55
class BzrlibAdapter < BzrAdapter
66

77
def setup
8-
@bzr_client = BzrPipeClient.new(url)
9-
@bzr_client.start
8+
bzr_client = BzrPipeClient.new(url)
9+
bzr_client.start
10+
bzr_client
1011
end
1112

1213
def bzr_client
13-
setup unless @bzr_client
14-
return @bzr_client
14+
@bzr_client ||= setup
1515
end
1616

1717
def cleanup

lib/ohloh_scm/adapters/hglib/client.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def send_command(cmd)
3636
# send the command
3737
@stdin.puts cmd
3838
@stdin.flush
39+
return if cmd == "QUIT"
3940

4041
# get status on stderr, first letter indicates state,
4142
# remaing value indicates length of the file content
@@ -55,6 +56,7 @@ def send_command(cmd)
5556

5657
def shutdown
5758
send_command("QUIT")
59+
[@stdout, @stdin, @stderr].each { |io| io.close unless io.closed? }
5860
Process.waitpid(@pid, Process::WNOHANG)
5961
end
6062
end

0 commit comments

Comments
 (0)