diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2013-12-17 14:18:58 -0800 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2013-12-17 14:18:58 -0800 |
| commit | 4b76a31c6d9fd9dd0c58b46a71c10d5061ed39eb (patch) | |
| tree | 1663c5bf814aec2517a62bbc4ce2cc3f84b084bb /src/pkg/runtime/malloc.goc | |
| parent | a1a3d213559861f407a9f5bc7db3c3ae0d7fe5c5 (diff) | |
| download | go-4b76a31c6d9fd9dd0c58b46a71c10d5061ed39eb.tar.xz | |
runtime: don't crash in SetFinalizer if sizeof *x is zero
And document it explicitly, even though it already said
it wasn't guaranteed.
Fixes #6857
R=golang-dev, khr
CC=golang-dev
https://golang.org/cl/43580043
Diffstat (limited to 'src/pkg/runtime/malloc.goc')
| -rw-r--r-- | src/pkg/runtime/malloc.goc | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/pkg/runtime/malloc.goc b/src/pkg/runtime/malloc.goc index cd124f0f71..b81fc398f0 100644 --- a/src/pkg/runtime/malloc.goc +++ b/src/pkg/runtime/malloc.goc @@ -760,12 +760,15 @@ func SetFinalizer(obj Eface, finalizer Eface) { runtime·printf("runtime.SetFinalizer: first argument is %S, not pointer\n", *obj.type->string); goto throw; } + ot = (PtrType*)obj.type; + if(ot->elem != nil && ot->elem->size == 0) { + return; + } if(!runtime·mlookup(obj.data, &base, &size, nil) || obj.data != base) { runtime·printf("runtime.SetFinalizer: pointer not at beginning of allocated block\n"); goto throw; } nret = 0; - ot = (PtrType*)obj.type; fint = nil; if(finalizer.type != nil) { if(finalizer.type->kind != KindFunc) |
