Skip to content

Commit

Permalink
Revert from COINIT_APARTMENTTHREADED to COINIT_MULTITHREADED
Browse files Browse the repository at this point in the history
This reverts commit df9318a.

We are still seeing a memory leak, just much slower.
About 120MB per day in scollector. I'll keep looking but pretty sure this commit
causes the issue.
  • Loading branch information
gbrayut committed Aug 11, 2016
1 parent 771c736 commit e54cbda
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 e54cbda

Please sign in to comment.