I see a couple of issues with your code.

The code you use for removal of an element is right. You've correctly made 
sure there is no leak.

You never return the clients slice back to the caller.  Any length 
shortening of the clients slice will be lost when the function returns.
You might want to 
review https://blog.golang.org/go-slices-usage-and-internals

I'm skeptical of using struct equality on your connInfo struct.  My guess 
is you just want the ipAddr and name fields to match, not the net.Conn 
itself.  It's hard for me to know for sure without seeing the users of this 
code, but it looks fishy.

You probably want a break statement at the end of your if block. Unless you 
expect multiple structs to match?

On Monday, September 25, 2017 at 5:14:22 PM UTC-7, kortschak wrote:
>
> This is not nice if you want to reuse the slice, and still may leak the 
> fields. 
>
> clients[i] = clients[len(clients)-1] 
> // If the current clients[i] is deleted it becomes inaccessible 
> // and the ipAddr, name and conn fields potentially leak, so 
> // zero them in the last position of the slice. 
> clients[len(clients)-1] = connInfo{} 
> clients = clients[:len(clients)-1] 
>
>
> On Mon, 2017-09-25 at 11:52 -0700, Tamás Gulácsi wrote: 
> > https://github.com/golang/go/wiki/SliceTricks 
> > 
> > clients[i] = clients[0] 
> > clients = clients[1:] 
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to