Gather: fix closable crash again

Add assert for nil pointer as well
This commit is contained in:
Sam Lancia
2020-06-06 03:17:05 -07:00
committed by Sean DuBois
parent 3884b2598e
commit b3ade1e219
3 changed files with 16 additions and 2 deletions
+1
View File
@@ -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
+3 -2
View File
@@ -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
}
+12
View File
@@ -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())
}