Skip to content

Commit

Permalink
fix memory leak in check_service/check_drivesize on windows (fixes #117)
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed May 6, 2024
1 parent 834baf6 commit cea9850
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ next:
- add native aarch64 (arm64) packages for windows
- add support for extending default filter/warn/crit
- check_service: use cgroup pids if no main pid available
- fix memory leak in check_service on windows
- fix memory leak in check_drivesize on windows
- fix missing scripts in inventory

0.23 Mon Apr 15 17:29:53 CEST 2024
Expand Down
3 changes: 3 additions & 0 deletions pkg/snclient/check_drivesize_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ func (l *CheckDrivesize) setVolumes(requiredDisks map[string]map[string]string)

return
}
defer func() {
LogDebug(windows.CloseHandle(hndl))
}()
volumes = append(volumes, syscall.UTF16ToString(volumeName))

for {
Expand Down
7 changes: 6 additions & 1 deletion pkg/snclient/check_service_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ func (l *CheckService) Check(ctx context.Context, _ *Agent, check *CheckData, _
Output: fmt.Sprintf("Failed to open service handler: %s", err),
}, nil
}
defer func() {
LogDebug(ctrlMgr.Disconnect())
}()

if len(l.services) == 0 || slices.Contains(l.services, "*") {
serviceList, err2 := ctrlMgr.ListServices()
Expand Down Expand Up @@ -185,7 +188,9 @@ func (l *CheckService) getServiceDetails(ctrlMgr *mgr.Mgr, service string) (*Win
return nil, fmt.Errorf("failed to open service %s: %s", service, err.Error())
}
ctlSvc := &mgr.Service{Name: service, Handle: *svcHdl}
defer ctlSvc.Close()
defer func() {
LogDebug(ctlSvc.Close())
}()

statusCode, err := ctlSvc.Query()
if err != nil {
Expand Down

0 comments on commit cea9850

Please sign in to comment.