Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small leak in makeAddress #62

Closed
lhoward opened this issue Aug 2, 2023 · 1 comment · Fixed by #63
Closed

Small leak in makeAddress #62

lhoward opened this issue Aug 2, 2023 · 1 comment · Fixed by #63

Comments

@lhoward
Copy link
Contributor

lhoward commented Aug 2, 2023

Thanks for the great software. A small leak found with leaks:

   public static func makeAddress(from addr: sockaddr_storage) throws -> Address {
       switch Int32(addr.ss_family) {
       case AF_INET:
           var addr_in = try sockaddr_in.make(from: addr)
           let maxLength = socklen_t(INET_ADDRSTRLEN)
           let buffer = UnsafeMutablePointer<CChar>.allocate(capacity: Int(maxLength))
           try Socket.inet_ntop(AF_INET, &addr_in.sin_addr, buffer, maxLength)
           return .ip4(String(cString: buffer), port: UInt16(addr_in.sin_port).byteSwapped)

       case AF_INET6:
           var addr_in6 = try sockaddr_in6.make(from: addr)
           let maxLength = socklen_t(INET6_ADDRSTRLEN)
           let buffer = UnsafeMutablePointer<CChar>.allocate(capacity: Int(maxLength))
           try Socket.inet_ntop(AF_INET6, &addr_in6.sin6_addr, buffer, maxLength)
           return .ip6(String(cString: buffer), port: UInt16(addr_in6.sin6_port).byteSwapped)
...
    }

buffer is leaked. Should be an easy fix.

@swhitty swhitty linked a pull request Aug 3, 2023 that will close this issue
@swhitty
Copy link
Owner

swhitty commented Aug 3, 2023

Thank you for reporting this. 🙏🏻

Fixed via #63

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants