Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

james/remove wmi unneeded releases #1863

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions ee/wmi/wmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,17 @@ func Query(ctx context.Context, slogger *slog.Logger, className string, properti
}
defer serviceRaw.Clear()

// In testing, we find we do not need to `service.Release()`. The memory of result is released
// by `defer serviceRaw.Clear()` above, furthermore on windows arm64 machines, calling
// `service.Clear()` after `serviceRaw.Release()` causes a panic.
//
// Looking at the `serviceRaw.ToIDispatch()` implementation, it's just a cast that returns
// a pointer to the same memory. Which would explain why calling `serviceRaw.Release()` after
// `service.Clear()` causes a panic. It's unclear why this causes a panic on arm64 machines and
// not on amd64 machines.
//
// This also applies to the `resultRaw` and `results` variables below.
service := serviceRaw.ToIDispatch()
defer service.Release()

slogger.Log(ctx, slog.LevelDebug,
"running WMI query",
Expand All @@ -168,8 +177,8 @@ func Query(ctx context.Context, slogger *slog.Logger, className string, properti
}
defer resultRaw.Clear()

// see above comment about `service.Release()` to explain why `result.Release()` isn't called
result := resultRaw.ToIDispatch()
defer result.Release()

if err := oleutil.ForEach(result, handler.HandleVariant); err != nil {
return nil, fmt.Errorf("ole foreach: %w", err)
Expand Down
Loading