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

Fix buffer leak #63

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions FlyingSocks/Sources/SocketAddress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,15 @@ extension Socket {
var addr_in = try sockaddr_in.make(from: addr)
let maxLength = socklen_t(INET_ADDRSTRLEN)
let buffer = UnsafeMutablePointer<CChar>.allocate(capacity: Int(maxLength))
defer { buffer.deallocate() }
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))
defer { buffer.deallocate() }
try Socket.inet_ntop(AF_INET6, &addr_in6.sin6_addr, buffer, maxLength)
return .ip6(String(cString: buffer), port: UInt16(addr_in6.sin6_port).byteSwapped)

Expand Down