Skip to content

fix: resource leaks in file and socket handling#21652

Open
lxcxjxhx wants to merge 1 commit into
rapid7:masterfrom
lxcxjxhx:fix/resource-leaks
Open

fix: resource leaks in file and socket handling#21652
lxcxjxhx wants to merge 1 commit into
rapid7:masterfrom
lxcxjxhx:fix/resource-leaks

Conversation

@lxcxjxhx

@lxcxjxhx lxcxjxhx commented Jul 7, 2026

Copy link
Copy Markdown

Problem

This PR fixes resource leaks in Metasploit Framework:

  1. lib/msf/ui/console/driver.rb: File handle leak in save_resource method - file opened without block form, not closed on exception
  2. lib/net/dns/resolver.rb: UDP socket leak in send_udp method - socket not closed on exception

Solution

  1. Use block form of File.open for automatic cleanup
  2. Add ensure block to close UDP socket

Impact

  • Prevents resource leaks when exceptions occur
  • Improves stability during long-running sessions
  • No breaking changes

- lib/msf/ui/console/driver.rb: Use block form of File.open in save_resource to ensure automatic file handle cleanup
- lib/net/dns/resolver.rb: Add ensure block to close UDP socket in send_udp method

These changes prevent resource leaks when exceptions occur during file or network operations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants