Repository navigation
Make IOObject and CFTypeRef AutoCloseable, migrate macOS call sites - #3292
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (12)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
🧰 Additional context used🧠 Learnings (3)📚 Learning: 2026-04-14T23:28:14.505ZApplied to files:
📚 Learning: 2026-04-15T04:56:15.707ZApplied to files:
📚 Learning: 2026-04-18T23:21:41.153ZApplied to files:
🔇 Additional comments (12)
📝 WalkthroughWalkthroughThis PR refactors FFM resource management across the oshi macOS driver layer. Base classes ChangesFFM Try-with-Resources Resource Management
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3292 +/- ##
============================================
- Coverage 75.77% 75.57% -0.20%
Complexity 76 76
============================================
Files 410 410
Lines 15812 15810 -2
Branches 2524 2528 +4
============================================
- Hits 11981 11949 -32
- Misses 2369 2386 +17
- Partials 1462 1475 +13
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Make IOObject and CFTypeRef implement AutoCloseable (delegating to their existing release() methods), enabling try-with-resources for IOKit and CoreFoundation object lifecycle management. Migrated call sites: - IOKitProviderFFM - MacDisplayFFM - MacFirmwareFFM - MacGpuStatsFFM - MacNetworkIfFFM - MacUsbDeviceFFM - MacOSProcessFFM - IOReportClientFFM - WindowInfoFFM Remaining for follow-up (complex patterns): - MacHWDiskStoreFFM (deeply nested, conditional releases) - MacSensorsFFM (smcClose takes int, not AutoCloseable) - MacPowerSourceFFM (multi-release with null checks) - MacFileSystemFFM (conditional releases) - IOKit.java (releaseCFObjects multi-release helper) - IOReportClientFFM (raw cfRelease with null checks) - MacNetworkParamsFFM (freeaddrinfo) - WhoFFM, MacCentralProcessorFFM, MacDisplayFFM (partial)
132e079 to
466ad76
Compare
* Fix native resource leaks in JNA module Add try/finally blocks to ensure native resources are released even when exceptions occur: - WindowsInternetProtocolStatsJNA: Wrap Memory buf in try/finally in all 4 connection query methods. Also fixes missing buf.close() in queryUDPv6Connections() which leaked on every call. Gate table parsing on ERROR_SUCCESS to avoid parsing buf on API failures. - WindowsDisplayJNA: Wrap hDevInfo and registry key in try/finally. - WindowsPowerSourceJNA: Wrap hdev (SetupDi handle) in try/finally. - MacHWDiskStoreJNA: Wrap DASession and CFStringRef releases in try/finally. Move try to start immediately after session null-check so mapCFKeys() failure cannot leak the session. - HkeyUserData: Wrap registry key usage in try/finally. - SessionWtsData: Wrap WTSFreeMemory calls in try/finally for both the session info buffer and individual query buffers. Guard WTSQuerySessionInformation calls by checking return value and null pointer before dereferencing. - ProcessWtsData: Wrap WTSFreeMemoryEx in try/finally. The FFM equivalents of these files already handle resource cleanup correctly (via Arena try-with-resources or NativeHandle). These fixes bring the JNA module to parity. * Fix SonarQube AutoCloseable findings for borrowed CF references Add static value-extraction methods to CFStringRef, CFNumberRef, CFBooleanRef, CFArrayRef, and CFDictionaryRef for use with borrowed (non-owned) CoreFoundation segments that must not be released. Migrate all call sites that wrap borrowed segments solely for value extraction. For owned references with gaps before try-with-resources, move creation directly into the try declaration. For framework-consumed references (IOKit matching dictionaries), add @SuppressWarnings with explanatory comments. Resolves 45 SonarQube blocker findings introduced when CFTypeRef was made AutoCloseable in #3292.
Make
IOObjectandCFTypeRefimplementAutoCloseable(delegating to their existingrelease()methods), enabling try-with-resources for IOKit and CoreFoundation object lifecycle management. This is PR 3 in the NativeHandle/AutoCloseable series (#3290, #3291).Infrastructure
IOKit.IOObjectnow implementsAutoCloseablewithclose()→release()CoreFoundation.CFTypeRefnow implementsAutoCloseablewithclose()→release()Migrated call sites (11 files)
IOKitProviderFFM,MacDisplayFFM,MacFirmwareFFM,MacGpuStatsFFMMacNetworkIfFFM,MacUsbDeviceFFM,MacOSProcessFFMIOReportClientFFM,WindowInfoFFMRemaining for follow-up
Complex patterns not addressed in this PR:
MacHWDiskStoreFFM— deeply nested with conditional releases and reassigned variablesMacSensorsFFM—smcClose(int)not AutoCloseableMacPowerSourceFFM,MacFileSystemFFM— multi-release with null checksIOKit.java—releaseCFObjects()multi-release helperIOReportClientFFM— rawcfReleasewith null checksMacNetworkParamsFFM—freeaddrinfo(not a release pattern)Summary by CodeRabbit