google / gnxi

gNXI Tools - gRPC Network Management/Operations Interface Tools
Apache License 2.0
260 stars 115 forks source link

Wrong usage of defer #76

Closed QiAnXinCodeSafe closed 5 years ago

QiAnXinCodeSafe commented 5 years ago

The defer statement must be placed after the error check. Otherwise listen may be nil. https://github.com/google/gnxi/blob/c14ccdb08c24e65e80106585d98bb07a40d65c30/gnoi_target/gnoi_target.go#L43-L47

sergeysergeevru commented 5 years ago

It should not be a problem. If log.Fatal happened defer part will not be executed.

QiAnXinCodeSafe commented 5 years ago

Yes, you are right. However, it is best to place the defer statement after the error check.