Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(546)

Delta Between Two Patch Sets: src/pkg/net/fd_unix.go

Issue 8318044: code review 8318044: net: fix possible runtime.PollDesc leak when connect or... (Closed)
Left Patch Set: diff -r 3346bb37412c https://code.google.com/p/go Created 10 years, 12 months ago
Right Patch Set: diff -r f2a65f5804ec https://code.google.com/p/go Created 10 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/pkg/net/sock_posix.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // +build darwin freebsd linux netbsd openbsd 5 // +build darwin freebsd linux netbsd openbsd
6 6
7 package net 7 package net
8 8
9 import ( 9 import (
10 "io" 10 "io"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 115 }
116 fd.sysmu.Unlock() 116 fd.sysmu.Unlock()
117 return nil 117 return nil
118 } 118 }
119 119
120 // Remove a reference to this FD and close if we've been asked to do so (and 120 // Remove a reference to this FD and close if we've been asked to do so (and
121 // there are no references left. 121 // there are no references left.
122 func (fd *netFD) decref() { 122 func (fd *netFD) decref() {
123 fd.sysmu.Lock() 123 fd.sysmu.Lock()
124 fd.sysref-- 124 fd.sysref--
125 » if fd.closing && fd.sysref == 0 && fd.sysfile != nil { 125 » if fd.closing && fd.sysref == 0 {
126 // Poller may want to unregister fd in readiness notification me chanism, 126 // Poller may want to unregister fd in readiness notification me chanism,
127 // so this must be executed before sysfile.Close(). 127 // so this must be executed before sysfile.Close().
128 fd.pd.Close() 128 fd.pd.Close()
dvyukov 2013/04/09 04:07:48 This can not be called twice, right?
129 » » fd.sysfile.Close() 129 » » if fd.sysfile != nil {
130 » » fd.sysfile = nil 130 » » » fd.sysfile.Close()
131 » » » fd.sysfile = nil
132 » » } else {
133 » » » closesocket(fd.sysfd)
134 » » }
131 fd.sysfd = -1 135 fd.sysfd = -1
132 } 136 }
133 fd.sysmu.Unlock() 137 fd.sysmu.Unlock()
134 }
135
136 func (fd *netFD) close() error {
dvyukov 2013/04/05 16:30:19 Why can't we use Close() instead of close()? As fa
mikio 2013/04/06 07:42:12 I just don't want to break Rémy's changeset: 15019
137 fd.pd.Evict()
138 fd.pd.Close()
139 return closesocket(fd.sysfd)
140 } 138 }
141 139
142 func (fd *netFD) Close() error { 140 func (fd *netFD) Close() error {
143 fd.pd.Lock() // needed for both fd.incref(true) and pollDesc.Evict 141 fd.pd.Lock() // needed for both fd.incref(true) and pollDesc.Evict
144 if err := fd.incref(true); err != nil { 142 if err := fd.incref(true); err != nil {
145 fd.pd.Unlock() 143 fd.pd.Unlock()
146 return err 144 return err
147 } 145 }
148 // Unblock any I/O. Once it all unblocks and returns, 146 // Unblock any I/O. Once it all unblocks and returns,
149 // so that it cannot be referring to fd.sysfd anymore, 147 // so that it cannot be referring to fd.sysfd anymore,
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 if err = syscall.SetNonblock(ns, false); err != nil { 421 if err = syscall.SetNonblock(ns, false); err != nil {
424 return nil, &OpError{"setnonblock", fd.net, fd.laddr, err} 422 return nil, &OpError{"setnonblock", fd.net, fd.laddr, err}
425 } 423 }
426 424
427 return os.NewFile(uintptr(ns), fd.name()), nil 425 return os.NewFile(uintptr(ns), fd.name()), nil
428 } 426 }
429 427
430 func closesocket(s int) error { 428 func closesocket(s int) error {
431 return syscall.Close(s) 429 return syscall.Close(s)
432 } 430 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b