Skip to content

Commit bf88dd7

Browse files
committed
Fixed possibly panic on certain error conditions (fixes #102)
1 parent e1bd20f commit bf88dd7

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

usbtransport.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,14 @@ func (transport *UsbTransport) RoundTripWithSession(session int,
461461
// This is important that context is is set after inter-request
462462
// or initial delay is already done, so we don't need to bother
463463
// with adjusting the timeout.
464+
//
465+
// The context cancel function is called from many places and
466+
// not always used, so for simplicity I'd better initialize it
467+
// to the dummy function rather that to compare it with nil
468+
// every time it is called.
464469
rwctx := context.Background()
465-
var cleanupCtx context.CancelFunc
470+
cleanupCtx := context.CancelFunc(func() {})
471+
466472
if transport.timeout != 0 {
467473
rwctx, cleanupCtx = context.WithTimeout(rwctx,
468474
transport.timeout)

0 commit comments

Comments
 (0)