[src] Fix numerous memory leaks.#24723
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request fixes numerous memory leaks in the codebase by properly releasing CoreFoundation array handles returned by "Copy" functions. CoreFoundation naming conventions dictate that functions with "Copy" in their name return objects with +1 retain count, requiring explicit release after use.
Changes:
- Added a new
NSArray.ArrayFromHandleoverload that accepts areleaseHandleparameter to release the native handle after conversion - Fixed memory leaks across Security, CoreVideo, CoreText, CoreServices, and AddressBook frameworks by using the new overload
- Fixed a critical bug in CTFontManager.cs where
CFRetainwas mistakenly called instead ofCFRelease
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Foundation/NSArray.cs | Added new ArrayFromHandle<T> overload with releaseHandle parameter for proper memory management |
| src/Security/Trust.cs | Fixed memory leak in GetCertificateChain() by releasing SecTrustCopyCertificateChain result |
| src/Security/SecTrust.cs | Fixed memory leaks in GetPolicies() and GetCustomAnchorCertificates() by releasing Copy function results |
| src/CoreVideo/CVPixelFormatDescription.cs | Fixed memory leak in AllTypes property by releasing CVPixelFormatDescriptionArrayCreateWithAllPixelFormatTypes result |
| src/CoreText/CTFontManager.cs | Fixed critical bug: changed CFRetain to CFRelease in ArrayFromHandle helper method |
| src/CoreServices/LaunchServices.cs | Fixed memory leaks in GetApplicationUrlsForUrl() and GetApplicationUrlsForBundleIdentifier() by releasing LSCopy function results |
| src/AddressBook/ABGroup.cs | Fixed memory leaks in GetEnumerator() and GetMembers() by releasing ABGroupCopyArrayOfAllMembers result |
| src/AddressBook/ABAddressBook.cs | Fixed memory leaks in multiple methods (GetPeople(), GetGroups(), GetAllSources()) by releasing ABAddressBookCopy function results |
✅ [PR Build #acac6ef] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ [CI Build #acac6ef] Build passed (Build packages) ✅Pipeline on Agent |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
✅ [CI Build #acac6ef] Build passed (Build macOS tests) ✅Pipeline on Agent |
💻 [CI Build #acac6ef] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
💻 [CI Build #acac6ef] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
💻 [CI Build #acac6ef] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
💻 [CI Build #acac6ef] Tests on macOS arm64 - Mac Sequoia (15) passed 💻✅ All tests on macOS arm64 - Mac Sequoia (15) passed. Pipeline on Agent |
💻 [CI Build #acac6ef] Tests on macOS arm64 - Mac Tahoe (26) passed 💻✅ All tests on macOS arm64 - Mac Tahoe (26) passed. Pipeline on Agent |
🚀 [CI Build #acac6ef] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 131 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
No description provided.