Fix memory leaks in the Windows (WinRT) backend#454
Closed
report02 wants to merge 1 commit into
Closed
Conversation
Many WinRT/COM objects returned from Get*, GetAt, GetResults, DetachBuffer, New*, and *Async calls were never released, causing significant leaks — some on hot paths (per advertisement packet, per read/write, per notification). This change pairs each of those calls with a Release()/Close() and fixes several related bugs: - gap_windows.go getScanResultFromArgs: drop the duplicate GetAdvertisement() call, release vectors, elements and buffers. - gap_windows.go Adapter.Connect: release bleDeviceOp, dID, gattSessionOp; release bleDevice/newSession on error paths. - gap_windows.go Device.Disconnect: use a pointer receiver + sync.Once on the underlying struct to guard against double-release. - gap_windows.go Advertisement.Configure: release vec, manData, buf, and release each writer per iteration instead of via defer. - gattc_windows.go DiscoverServices / DiscoverCharacteristics: release op, result, vector; close unmatched services/characteristics; fix loop-variable capture in the srv.Close() goroutine. - gattc_windows.go DeviceCharacteristic.Read: release readOp, result, buffer, datareader. - gattc_windows.go write/EnableNotificationsWithMode: release asyncOp and writeOp. - gatts_windows.go AddService: release op/result/localService/params/ createCharOp/characteristicResults and unkept characteristics; keep serviceProvider, handler tokens and handlers tracked in a package map keyed by UUID so RemoveService can stop & release them. - gatts_windows.go RemoveService: stop the previously-started provider, remove handler registrations, and release everything (instead of creating a brand-new provider). - gatts_windows.go write/read requested handlers: release reqAsyncOp, gattWriteRequest/gattReadRequest, and the GetValue buffer. - bufferToSlice now releases its IBuffer argument.
Member
Author
|
Yes. Sorry I posted it too soon. |
Member
No problem! Thank you for contributing! Let me know if you need some help |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Many WinRT/COM objects returned from Get*, GetAt, GetResults, DetachBuffer, New*, and *Async calls were never released, causing significant leaks — some on hot paths (per advertisement packet, per read/write, per notification). This change pairs each of those calls with a Release()/Close() and fixes several related bugs: