Skip to content

Commit 007b3de

Browse files
author
lsanchez-r7
committed
Merge pull request rapid7#2271 from bturner-r7/bug/db-leaks
Land rapid7#2271, Fix database connection leaks
2 parents c660279 + cd45c77 commit 007b3de

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lib/msf/core/db.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,7 @@ def report_auth_info(opts={})
15121512
raise ArgumentError.new("Invalid address or object for :host (#{opts[:host].inspect})")
15131513
end
15141514

1515+
::ActiveRecord::Base.connection_pool.with_connection {
15151516
host = opts.delete(:host)
15161517
ptype = opts.delete(:type) || "password"
15171518
token = [opts.delete(:user), opts.delete(:pass)]
@@ -1623,6 +1624,7 @@ def report_auth_info(opts={})
16231624
end
16241625

16251626
ret[:cred] = cred
1627+
}
16261628
end
16271629

16281630
alias :report_cred :report_auth_info
@@ -1922,8 +1924,10 @@ def report_vuln_details(vuln, details)
19221924
# Note that this *can* update data across workspaces
19231925
#
19241926
def update_vuln_details(details)
1927+
::ActiveRecord::Base.connection_pool.with_connection {
19251928
criteria = details.delete(:key) || {}
19261929
::Mdm::VulnDetail.update(key, details)
1930+
}
19271931
end
19281932

19291933
#

lib/msf/core/session_manager.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,17 @@ def initialize(framework)
107107
# processing time for large session lists from skewing our update interval.
108108

109109
last_seen_timer = Time.now.utc
110-
values.each do |s|
111-
# Update the database entry on a regular basis, marking alive threads
112-
# as recently seen. This notifies other framework instances that this
113-
# session is being maintained.
114-
if framework.db.active and s.db_record
115-
s.db_record.last_seen = Time.now.utc
116-
s.db_record.save
110+
if framework.db.active
111+
::ActiveRecord::Base.connection_pool.with_connection do
112+
values.each do |s|
113+
# Update the database entry on a regular basis, marking alive threads
114+
# as recently seen. This notifies other framework instances that this
115+
# session is being maintained.
116+
if s.db_record
117+
s.db_record.last_seen = Time.now.utc
118+
s.db_record.save
119+
end
120+
end
117121
end
118122
end
119123
end

0 commit comments

Comments
 (0)