You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2020/05/24 15:29:25 UTC

[GitHub] [dubbo-go] flycash commented on a change in pull request #539: Fix: defer in loop will cause resource leak

flycash commented on a change in pull request #539:
URL: https://github.com/apache/dubbo-go/pull/539#discussion_r429648029



##########
File path: config/service_config.go
##########
@@ -119,8 +119,8 @@ func getRandomPort(protocolConfigs []*ProtocolConfig) *list.List {
 		if err != nil {
 			panic(perrors.New(fmt.Sprintf("Get tcp port error,err is {%v}", err)))
 		}
-		defer tcp.Close()
 		ports.PushBack(strings.Split(tcp.Addr().String(), ":")[1])
+		tcp.Close()

Review comment:
       I am not very sure whether `tcp.Addr().String()` will return something like "127.0.0.1" which will cause `ports.PushBack(strings.Split(tcp.Addr().String(), ":")[1])` panic.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org