net: IP.To4 retains reference to IPv6 IP #10104
Calling .To4 on an IPv6 IP, returns a slice of the IPv4 part of the address. Elsewhere new buffers are allocated instead, and it's natural to assume this is the case for To4 as well. User code can proceed assuming it now owns the contents of net.IP which is not correct.
To4 converts the IPv4 address ip to a 4-byte representation. If ip is not an IPv4 address, To4 returns nil. There is no guarantee the returned IP is freshly allocated.
The text was updated successfully, but these errors were encountered: