From dea84cf1fb2934a30b28901374d6faa3a9fbf8fb Mon Sep 17 00:00:00 2001 From: adwpc Date: Fri, 10 Apr 2020 00:05:33 +0800 Subject: [PATCH] Fix closeable panic Fix closeable panic when conn == nil --- README.md | 1 + gather.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index 185e984..7ccf92f 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu * [Jason Maldonis](https://github.com/jjmaldonis) * [Nevio Vesic](https://github.com/0x19) * [David Hamilton](https://github.com/dihamilton) +* [adwpc](https://github.com/adwpc) ### License MIT License - see [LICENSE](LICENSE) for full text diff --git a/gather.go b/gather.go index 2c8dbb8..42c3a35 100644 --- a/gather.go +++ b/gather.go @@ -22,6 +22,11 @@ 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") + return + } + log.Warnf(msg) if err := c.Close(); err != nil { log.Warnf("Failed to close conn: %v", err)