Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Commit

Permalink
Partial Revert "Correct threading model used by wmi calls"
Browse files Browse the repository at this point in the history
This reverts part of commit 04850ec.

using COINIT_APARTMENTTHREADED caused a memory leak.
See Unity-Technologies#8
  • Loading branch information
gbrayut committed Jul 27, 2016
1 parent 04850ec commit d4ae5b4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion wmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"runtime"
"strconv"
"strings"
"sync"
"time"

"github.com/go-ole/go-ole"
Expand All @@ -47,6 +48,7 @@ var (
// ErrNilCreateObject is the error returned if CreateObject returns nil even
// if the error was nil.
ErrNilCreateObject = errors.New("wmi: create object returned nil")
lock sync.Mutex
)

// S_FALSE is returned by CoInitializeEx if it was already called on this thread.
Expand Down Expand Up @@ -123,10 +125,12 @@ func (c *Client) Query(query string, dst interface{}, connectServerArgs ...inter
return ErrInvalidEntityType
}

lock.Lock()
defer lock.Unlock()
runtime.LockOSThread()
defer runtime.UnlockOSThread()

err := ole.CoInitializeEx(0, ole.COINIT_APARTMENTTHREADED)
err := ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED)
if err != nil {
oleCode := err.(*ole.OleError).Code()
if oleCode != ole.S_OK && oleCode != S_FALSE {
Expand Down

0 comments on commit d4ae5b4

Please sign in to comment.