diff --git a/util/socketset/socketset.go b/util/socketset/socketset.go index 2ad7d357..c2b5d316 100644 --- a/util/socketset/socketset.go +++ b/util/socketset/socketset.go @@ -83,6 +83,10 @@ func NewSocketSet(groups uint32, name string, proto int) (*SocketSet, error) { // to the message length. It will block until an event is produced, or shutdown // is called. func (obj *SocketSet) ReceiveBytes() ([]byte, error) { + if obj == nil { + return nil, fmt.Errorf("nil object") // caller used this incorrectly + } + // Select will return when any fd in fdSet (fdEvents and fdPipe) is ready // to read. _, err := unix.Select(obj.nfd(), obj.fdSet(), nil, nil, nil) @@ -180,6 +184,10 @@ Loop: // message to the pipe file descriptor. It must be called before close, and // should only be called once. func (obj *SocketSet) Shutdown() error { + if obj == nil { + return fmt.Errorf("nil object") // caller used this incorrectly + } + // close the event socket so no more events are produced if err := unix.Close(obj.fdEvents); err != nil { return err @@ -193,6 +201,10 @@ func (obj *SocketSet) Shutdown() error { // Close closes the pipe file descriptor. It must only be called after Shutdown // has closed fdEvents, and unblocked receive. It should only be called once. func (obj *SocketSet) Close() error { + if obj == nil { + return fmt.Errorf("nil object") // caller used this incorrectly + } + if err := unix.Unlink(obj.pipeFile); err != nil { return errwrap.Wrapf(err, "could not unbind %s", obj.pipeFile) } diff --git a/util/socketset/socketset_test.go b/util/socketset/socketset_test.go index f473f13b..adf48831 100644 --- a/util/socketset/socketset_test.go +++ b/util/socketset/socketset_test.go @@ -114,6 +114,7 @@ func TestShutdown(t *testing.T) { ss, err := NewSocketSet(0, "pipe.sock", 0) if err != nil { t.Errorf("could not create SocketSet: %+v", err) + return } // waitgroup for netlink receive goroutine wg := &sync.WaitGroup{}