tsdb: fix handle leak on mmap failure on MS Windows (#17310)
Some checks are pending
buf.build / lint and publish (push) Waiting to run
CI / Go tests (push) Waiting to run
CI / More Go tests (push) Waiting to run
CI / Go tests with previous Go version (push) Waiting to run
CI / UI tests (push) Waiting to run
CI / Go tests on Windows (push) Waiting to run
CI / Mixins tests (push) Waiting to run
CI / Build Prometheus for common architectures (push) Waiting to run
CI / Build Prometheus for all architectures (push) Waiting to run
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
CI / Check generated parser (push) Waiting to run
CI / golangci-lint (push) Waiting to run
CI / fuzzing (push) Waiting to run
CI / codeql (push) Waiting to run
CI / Publish main branch artifacts (push) Blocked by required conditions
CI / Publish release artefacts (push) Blocked by required conditions
CI / Publish UI on npm Registry (push) Blocked by required conditions
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run

Signed-off-by: Jarkko Pöyry <jarkko.poyry@metaplay.io>
This commit is contained in:
Jarkko Pöyry 2025-12-21 21:55:02 +02:00 committed by GitHub
parent a155ad55a3
commit e4b6d443fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -27,14 +27,15 @@ func mmap(f *os.File, size int) ([]byte, error) {
}
addr, errno := syscall.MapViewOfFile(h, syscall.FILE_MAP_READ, 0, 0, uintptr(size))
if addr == 0 {
return nil, os.NewSyscallError("MapViewOfFile", errno)
}
if err := syscall.CloseHandle(syscall.Handle(h)); err != nil {
return nil, os.NewSyscallError("CloseHandle", err)
}
if addr == 0 {
return nil, os.NewSyscallError("MapViewOfFile", errno)
}
return (*[maxMapSize]byte)(unsafe.Pointer(addr))[:size], nil
}