collector: release HCS result documents on operation failure (#2600)

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2026-10-09 11:13:36 +02:00
committed by GitHub
parent 7391ece210
commit 74ab95f5dd
2 changed files with 93 additions and 5 deletions
+13 -5
View File
@@ -60,14 +60,22 @@ func WaitForOperationResult(operation Operation, timeout uint32) (string, error)
var resultDocument *uint16
r1, _, _ := procHcsWaitForOperationResult.Call(uintptr(operation), uintptr(timeout), uintptr(unsafe.Pointer(&resultDocument)))
if r1 != 0 {
return "", fmt.Errorf("HcsWaitForOperationResult failed: HRESULT 0x%X: %w", r1, Win32FromHResult(r1))
return consumeOperationResult(r1, resultDocument, windows.CoTaskMemFree)
}
// consumeOperationResult releases every caller-owned result document, including
// the diagnostic documents returned by failed operations.
func consumeOperationResult(resultCode uintptr, resultDocument *uint16, release func(unsafe.Pointer)) (string, error) {
if resultDocument != nil {
defer release(unsafe.Pointer(resultDocument))
}
result := windows.UTF16PtrToString(resultDocument)
windows.CoTaskMemFree(unsafe.Pointer(resultDocument))
if resultCode != 0 {
return "", fmt.Errorf("HcsWaitForOperationResult failed: HRESULT 0x%X: %w", resultCode, Win32FromHResult(resultCode))
}
return result, nil
return windows.UTF16PtrToString(resultDocument), nil
}
// CloseOperation closes an operation.