diff options
| author | Russ Cox <rsc@golang.org> | 2011-10-13 16:58:04 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2011-10-13 16:58:04 -0400 |
| commit | f58ed4e64126b595efbde9df04e63c7ea2a4fbd6 (patch) | |
| tree | 96948e47d2e0751de6c51e6d941ed8defaf70fc6 /src | |
| parent | d65aaf24a6f7c4752aa5609f3f40433218483e72 (diff) | |
| download | go-f58ed4e64126b595efbde9df04e63c7ea2a4fbd6.tar.xz | |
gc: disallow close on receive-only channels
Fixes #2353.
Fixes #2246.
R=golang-dev, r, gri
CC=golang-dev
https://golang.org/cl/5282042
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/gc/typecheck.c | 4 | ||||
| -rw-r--r-- | src/pkg/runtime/chan.c | 3 |
2 files changed, 7 insertions, 0 deletions
diff --git a/src/cmd/gc/typecheck.c b/src/cmd/gc/typecheck.c index 052fc74dff..0b2e6f0ca6 100644 --- a/src/cmd/gc/typecheck.c +++ b/src/cmd/gc/typecheck.c @@ -984,6 +984,10 @@ reswitch: yyerror("invalid operation: %#N (non-chan type %T)", n, t); goto error; } + if(!(t->chan & Csend)) { + yyerror("invalid operation: %#N (cannot close receive-only channel)", n); + goto error; + } ok |= Etop; goto ret; diff --git a/src/pkg/runtime/chan.c b/src/pkg/runtime/chan.c index cc056f65f1..475da233c1 100644 --- a/src/pkg/runtime/chan.c +++ b/src/pkg/runtime/chan.c @@ -1052,6 +1052,9 @@ runtime·closechan(Hchan *c) SudoG *sg; G* gp; + if(c == nil) + runtime·panicstring("close of nil channel"); + if(runtime·gcwaiting) runtime·gosched(); |
