Skip to content

Commit

Permalink
[release-branch.go1.3] runtime: fix defer of nil func
Browse files Browse the repository at this point in the history
««« CL 105140044 / c2832405e9b9
runtime: fix defer of nil func

Fixes #8047.

LGTM=r, iant
R=golang-codereviews, r, iant
CC=dvyukov, golang-codereviews, khr
https://golang.org/cl/105140044
»»»

LGTM=r
R=golang-codereviews, r
CC=adg, golang-codereviews, iant
https://golang.org/cl/103370044
  • Loading branch information
rsc committed Jun 12, 2014
1 parent ad02e9a commit 5c196b8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/pkg/runtime/stack.c
Expand Up @@ -856,7 +856,12 @@ runtime·newstack(void)
void
runtime·gostartcallfn(Gobuf *gobuf, FuncVal *fv)
{
runtime·gostartcall(gobuf, fv->fn, fv);
void *fn;

fn = nil;
if(fv != nil)
fn = fv->fn;
runtime·gostartcall(gobuf, fn, fv);
}

// Maybe shrink the stack being used by gp.
Expand Down
22 changes: 22 additions & 0 deletions test/fixedbugs/issue8047b.go
@@ -0,0 +1,22 @@
// run

// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Issue 8047. Defer setup during panic shouldn't crash for nil defer.

package main

func main() {
defer func() {
recover()
}()
f()
}

func f() {
var g func()
defer g()
panic(1)
}

0 comments on commit 5c196b8

Please sign in to comment.