From 7d79c723e5f2df429df65f590a3554a5e87c31cd Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Fri, 22 May 2020 08:26:43 -0700 Subject: [PATCH] Fix Windows memory leak (#9680) When running a zoned setup simply uploading will run the system out of memory very fast. Root cause: nFileSystemNameSize is a DWORD and not a pointer. No idea how this didn't crash hard. Furthermore replace poor mans utf16 -> string conversion to support arbitrary output. Fixes #9630 --- pkg/disk/type_windows.go | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/pkg/disk/type_windows.go b/pkg/disk/type_windows.go index 9b6e5a6af..f303090d3 100644 --- a/pkg/disk/type_windows.go +++ b/pkg/disk/type_windows.go @@ -31,10 +31,10 @@ var ( // getFSType returns the filesystem type of the underlying mounted filesystem func getFSType(path string) string { - var volumeNameSize uint32 = 260 - var nFileSystemNameSize, lpVolumeSerialNumber uint32 + volumeNameSize, nFileSystemNameSize := uint32(260), uint32(260) + var lpVolumeSerialNumber uint32 var lpFileSystemFlags, lpMaximumComponentLength uint32 - var lpFileSystemNameBuffer, volumeName [260]byte + var lpFileSystemNameBuffer, volumeName [130]uint16 var ps = syscall.StringToUTF16Ptr(filepath.VolumeName(path)) // Extract values safely @@ -56,15 +56,7 @@ func getFSType(path string) string { uintptr(unsafe.Pointer(&lpMaximumComponentLength)), uintptr(unsafe.Pointer(&lpFileSystemFlags)), uintptr(unsafe.Pointer(&lpFileSystemNameBuffer)), - uintptr(unsafe.Pointer(&nFileSystemNameSize)), 0) - var bytes []byte - if lpFileSystemNameBuffer[6] == 0 { - bytes = []byte{lpFileSystemNameBuffer[0], lpFileSystemNameBuffer[2], - lpFileSystemNameBuffer[4]} - } else { - bytes = []byte{lpFileSystemNameBuffer[0], lpFileSystemNameBuffer[2], - lpFileSystemNameBuffer[4], lpFileSystemNameBuffer[6]} - } + uintptr(nFileSystemNameSize)) - return string(bytes) + return syscall.UTF16ToString(lpFileSystemNameBuffer[:]) }