summaryrefslogtreecommitdiff
path: root/src/runtime/debug
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2014-12-08 20:04:56 -0800
committerKeith Randall <khr@golang.org>2014-12-10 16:33:26 +0000
commitb796cbc40657e0891a43bffab0ffb92ce656d8f1 (patch)
tree66d700763b5f05903e9edace719b55bb5ffb0349 /src/runtime/debug
parent508a22d5bcec2508779fbc4e3e4c745ffe8ea961 (diff)
downloadgo-git-b796cbc40657e0891a43bffab0ffb92ce656d8f1.tar.gz
runtime: fix finalizer iterator
It could only handle one finalizer before it raised an out-of-bounds error. Fixes issue #9172 Change-Id: Ibb4d0c8aff2d78a1396e248c7129a631176ab427 Reviewed-on: https://go-review.googlesource.com/1201 Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/runtime/debug')
-rw-r--r--src/runtime/debug/heapdump_test.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/runtime/debug/heapdump_test.go b/src/runtime/debug/heapdump_test.go
index 9201901151..cf01f52015 100644
--- a/src/runtime/debug/heapdump_test.go
+++ b/src/runtime/debug/heapdump_test.go
@@ -31,3 +31,40 @@ func TestWriteHeapDumpNonempty(t *testing.T) {
t.Fatalf("Heap dump size %d bytes, expected at least %d bytes", size, minSize)
}
}
+
+
+type Obj struct {
+ x, y int
+}
+
+func objfin(x *Obj) {
+ println("finalized", x)
+}
+
+func TestWriteHeapDumpFinalizers(t *testing.T) {
+ if runtime.GOOS == "nacl" {
+ t.Skip("WriteHeapDump is not available on NaCl.")
+ }
+ f, err := ioutil.TempFile("", "heapdumptest")
+ if err != nil {
+ t.Fatalf("TempFile failed: %v", err)
+ }
+ defer os.Remove(f.Name())
+ defer f.Close()
+
+ // bug 9172: WriteHeapDump couldn't handle more than one finalizer
+ println("allocating objects")
+ x := &Obj{}
+ runtime.SetFinalizer(x, objfin)
+ y := &Obj{}
+ runtime.SetFinalizer(y, objfin)
+
+ // Trigger collection of x and y, queueing of their finalizers.
+ println("starting gc")
+ runtime.GC()
+
+ // Make sure WriteHeapDump doesn't fail with multiple queued finalizers.
+ println("starting dump")
+ WriteHeapDump(f.Fd())
+ println("done dump")
+}