runtime: AddCleanup is not robust to arg values pointing to struct embedded data #72001
Labels
BugReport
Issues describing a possible bug in the Go implementation.
compiler/runtime
Issues related to the Go compiler and/or runtime.
Documentation
Issues describing a change to documentation.
NeedsFix
The path to resolution is known, but the work has not been done.
Milestone
Go version
go version go1.25-20250216-RC00 cl/727547642 +d524e1eccd X:fieldtrack,boringcrypto linux/amd64
Output of
go env
in your module/workspace:What did you do?
I noticed that
runtime.AddCleanup
does not robustly handle a case like this:What did you see happen?
The runtime panics:
What did you expect to see?
I would expect that this snippet of code to be more robust to the case of struct embedding (if that is at all possible), or the documentation for
runtime.AddFunc
also mention that naive struct embedding of the data that needs to be cleaned up into an outer struct won't work due to how alignment of memory works.We found a workaround by amending the definition of the outer type as follows:
The text was updated successfully, but these errors were encountered: