From 36207a91d3c97a9c64984572af89727495310469 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 12 Jun 2014 16:34:36 -0400 Subject: [PATCH] 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 --- src/pkg/runtime/stack.c | 7 ++++++- test/fixedbugs/issue8047b.go | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/fixedbugs/issue8047b.go diff --git a/src/pkg/runtime/stack.c b/src/pkg/runtime/stack.c index 4b66e7dbaa..1f7c2eaada 100644 --- a/src/pkg/runtime/stack.c +++ b/src/pkg/runtime/stack.c @@ -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. diff --git a/test/fixedbugs/issue8047b.go b/test/fixedbugs/issue8047b.go new file mode 100644 index 0000000000..de6acaab59 --- /dev/null +++ b/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) +}