You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: