mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Make sure err never gets masked
Defining err as named return parameter will make sure the variable gets assigned before returning and thus avoid masking Docker-DCO-1.1-Signed-off-by: Johannes 'fish' Ziemke <github@freigeist.org> (github: discordianfish)
This commit is contained in:
parent
c11660169a
commit
32bc865879
1 changed files with 10 additions and 13 deletions
|
@ -37,24 +37,16 @@ func SetIptablesChain(c *iptables.Chain) {
|
|||
chain = c
|
||||
}
|
||||
|
||||
func Map(container net.Addr, hostIP net.IP, hostPort int) (net.Addr, error) {
|
||||
func Map(container net.Addr, hostIP net.IP, hostPort int) (host net.Addr, err error) {
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
|
||||
var (
|
||||
m *mapping
|
||||
err error
|
||||
proto string
|
||||
allocatedHostPort int
|
||||
)
|
||||
|
||||
// release the port on any error during return.
|
||||
defer func() {
|
||||
if err != nil {
|
||||
portallocator.ReleasePort(hostIP, proto, allocatedHostPort)
|
||||
}
|
||||
}()
|
||||
|
||||
switch container.(type) {
|
||||
case *net.TCPAddr:
|
||||
proto = "tcp"
|
||||
|
@ -77,14 +69,19 @@ func Map(container net.Addr, hostIP net.IP, hostPort int) (net.Addr, error) {
|
|||
container: container,
|
||||
}
|
||||
default:
|
||||
err = ErrUnknownBackendAddressType
|
||||
return nil, err
|
||||
return nil, ErrUnknownBackendAddressType
|
||||
}
|
||||
|
||||
// release the allocated port on any further error during return.
|
||||
defer func() {
|
||||
if err != nil {
|
||||
portallocator.ReleasePort(hostIP, proto, allocatedHostPort)
|
||||
}
|
||||
}()
|
||||
|
||||
key := getKey(m.host)
|
||||
if _, exists := currentMappings[key]; exists {
|
||||
err = ErrPortMappedForIP
|
||||
return nil, err
|
||||
return nil, ErrPortMappedForIP
|
||||
}
|
||||
|
||||
containerIP, containerPort := getIPAndPort(m.container)
|
||||
|
|
Loading…
Reference in a new issue