mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-03-06 18:46:36 +00:00
Move netapi free back to a defer statement
Signed-off-by: Ben Ridley <benridley29@gmail.com>
This commit is contained in:
@@ -75,17 +75,19 @@ func netApiBufferFree(buffer *wKSTAInfo102) {
|
|||||||
// NetWkstaGetInfo returns information about the configuration of a workstation.
|
// NetWkstaGetInfo returns information about the configuration of a workstation.
|
||||||
// WARNING: The caller must call netApiBufferFree to free the memory allocated by this function.
|
// WARNING: The caller must call netApiBufferFree to free the memory allocated by this function.
|
||||||
// https://docs.microsoft.com/en-us/windows/win32/api/lmwksta/nf-lmwksta-netwkstagetinfo
|
// https://docs.microsoft.com/en-us/windows/win32/api/lmwksta/nf-lmwksta-netwkstagetinfo
|
||||||
func netWkstaGetInfo() (*wKSTAInfo102, uint32, error) {
|
func netWkstaGetInfo() (wKSTAInfo102, uint32, error) {
|
||||||
var lpwi *wKSTAInfo102
|
var lpwi *wKSTAInfo102
|
||||||
pLevel := uintptr(102)
|
pLevel := uintptr(102)
|
||||||
|
|
||||||
r1, _, _ := procNetWkstaGetInfo.Call(0, pLevel, uintptr(unsafe.Pointer(&lpwi)))
|
r1, _, _ := procNetWkstaGetInfo.Call(0, pLevel, uintptr(unsafe.Pointer(&lpwi)))
|
||||||
|
defer netApiBufferFree(lpwi)
|
||||||
|
|
||||||
if ret := *(*uint32)(unsafe.Pointer(&r1)); ret != 0 {
|
if ret := *(*uint32)(unsafe.Pointer(&r1)); ret != 0 {
|
||||||
return nil, ret, errors.New(NetApiStatus[ret])
|
return wKSTAInfo102{}, ret, errors.New(NetApiStatus[ret])
|
||||||
}
|
}
|
||||||
|
|
||||||
return lpwi, 0, nil
|
deref := *lpwi
|
||||||
|
return deref, 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetWorkstationInfo is an idiomatic wrapper for netWkstaGetInfo
|
// GetWorkstationInfo is an idiomatic wrapper for netWkstaGetInfo
|
||||||
@@ -103,7 +105,5 @@ func GetWorkstationInfo() (WorkstationInfo, error) {
|
|||||||
LanRoot: windows.UTF16PtrToString(info.wki102_lanroot),
|
LanRoot: windows.UTF16PtrToString(info.wki102_lanroot),
|
||||||
LoggedOnUsers: info.wki102_logged_on_users,
|
LoggedOnUsers: info.wki102_logged_on_users,
|
||||||
}
|
}
|
||||||
// Free the memory allocated by netapi
|
|
||||||
netApiBufferFree(info)
|
|
||||||
return workstationInfo, nil
|
return workstationInfo, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user