Skip to content

runtime: SetFinalizer doesn't work on pointers to empty structs #6857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bradfitz opened this issue Dec 1, 2013 · 6 comments
Closed

runtime: SetFinalizer doesn't work on pointers to empty structs #6857

bradfitz opened this issue Dec 1, 2013 · 6 comments
Labels
Documentation Issues describing a change to documentation. FrozenDueToAge
Milestone

Comments

@bradfitz
Copy link
Contributor

bradfitz commented Dec 1, 2013

runtime.SetFinalizer crashes at runtime if you register a finalizer on an empty struct.

package main

import "runtime"

type T struct{ i int }
type TE struct{}

func main() {
        t := new(T)
        te := new(TE)
        runtime.SetFinalizer(t, func(*T) {})
        runtime.SetFinalizer(te, func(*TE) {}) // runtime crash
}

With:

runtime.SetFinalizer: pointer not at beginning of allocated block
fatal error: runtime.SetFinalizer


Go tip (basically Go 1.2)
@rsc
Copy link
Contributor

rsc commented Dec 1, 2013

Comment 1:

Too bad I guess. Zero-size values are not allocations - they all return the same
pointer, which is not part of the standard heap. Setting a finalizer on that would not
be useful, since it is never freed.
We aren't going to remove this optimization, so either we should make SetFinalizer just
be a no-op in this case or document that it is invalid to use SetFinalizer on blocks of
size zero.

Labels changed: added go1.3, documentation, removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 2:

Labels changed: added release-go1.3.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 3:

Labels changed: removed go1.3.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 4:

Labels changed: added repo-main.

@bradfitz
Copy link
Contributor Author

Comment 5:

Sent https://golang.org/cl/43580043

Status changed to Started.

@bradfitz
Copy link
Contributor Author

Comment 6:

This issue was closed by revision 4b76a31.

Status changed to Fixed.

@bradfitz bradfitz added fixed Documentation Issues describing a change to documentation. labels Dec 17, 2013
@rsc rsc added this to the Go1.3 milestone Apr 14, 2015
@rsc rsc removed the release-go1.3 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation Issues describing a change to documentation. FrozenDueToAge
Projects
None yet
Development

No branches or pull requests

3 participants