mirror of
https://github.com/netbirdio/ice.git
synced 2026-05-22 17:10:58 -07:00
Gather: fix closable crash again
Add assert for nil pointer as well
This commit is contained in:
@@ -50,6 +50,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu
|
||||
* [David Hamilton](https://github.com/dihamilton)
|
||||
* [adwpc](https://github.com/adwpc)
|
||||
* [Ori Bernstein](https://eigenstate.org)
|
||||
* [Sam Lancia](https://github.com/nerd2)
|
||||
|
||||
### License
|
||||
MIT License - see [LICENSE](LICENSE) for full text
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net"
|
||||
"reflect"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -22,8 +23,8 @@ type closeable interface {
|
||||
|
||||
// Close a net.Conn and log if we have a failure
|
||||
func closeConnAndLog(c closeable, log logging.LeveledLogger, msg string) {
|
||||
if c == nil {
|
||||
log.Warnf("Conn is not allocated")
|
||||
if c == nil || (reflect.ValueOf(c).Kind() == reflect.Ptr && reflect.ValueOf(c).IsNil()) {
|
||||
log.Warnf("Conn is not allocated (%s)", msg)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -256,3 +256,15 @@ func TestTURNConcurrency(t *testing.T) {
|
||||
runTest(ProtoTypeUDP, SchemeTypeTURNS, nil, serverListener, serverPort)
|
||||
})
|
||||
}
|
||||
|
||||
func TestCloseConnLog(t *testing.T) {
|
||||
a, err := NewAgent(&AgentConfig{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
closeConnAndLog(nil, a.log, "normal nil")
|
||||
|
||||
var nc *net.UDPConn
|
||||
closeConnAndLog(nc, a.log, "nil ptr")
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user