From 5c46efb4d1c3545bd270b7bea97fc00b1abc5181 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 31 Jul 2025 13:51:17 +0200 Subject: [PATCH] runtime: implement dummy AddCleanup --- src/runtime/runtime.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go index 6bd719f54..7ad482a05 100644 --- a/src/runtime/runtime.go +++ b/src/runtime/runtime.go @@ -106,6 +106,25 @@ func UnlockOSThread() { // point of the call. func KeepAlive(x interface{}) +// AddCleanup is a dummy cleanup implementation. It doesn't do any cleaning up. +// +// We base this on the following loophole in the official runtime.AddCleanup +// documentation: +// +// > The cleanup(arg) call is not always guaranteed to run; in particular it is +// > not guaranteed to run before program exit. +// +// So it's technically correct (the best kind of correct) to not run any +// cleanups. But of course, this can lead to resource leaks so cleanups may need +// to be implemented eventually. +func AddCleanup[T, S any](ptr *T, cleanup func(S), arg S) Cleanup { + return Cleanup{} +} + +type Cleanup struct{} + +func (c Cleanup) Stop() {} + var godebugUpdate func(string, string) //go:linkname godebug_setUpdate internal/godebug.setUpdate