feat: fixed crash when releasing NVMe interface

This commit is contained in:
Serhiy Mytrovtsiy
2023-04-24 18:43:25 +02:00
parent 0ad7442f20
commit a8e14cb74a
2 changed files with 11 additions and 3 deletions

View File

@@ -166,14 +166,22 @@ internal class CapacityReader: Reader<Disks> {
var result = IOCreatePlugInInterfaceForService(disk, kIONVMeSMARTUserClientTypeID, kIOCFPlugInInterfaceID, &pluginInterface, &score)
guard result == kIOReturnSuccess else { return nil }
defer { IODestroyPlugInInterface(pluginInterface) }
defer {
if pluginInterface != nil {
IODestroyPlugInInterface(pluginInterface)
}
}
result = withUnsafeMutablePointer(to: &smartInterface) {
$0.withMemoryRebound(to: Optional<LPVOID>.self, capacity: 1) {
pluginInterface?.pointee?.pointee.QueryInterface(pluginInterface, CFUUIDGetUUIDBytes(kIONVMeSMARTInterfaceID), $0) ?? KERN_NOT_FOUND
}
}
defer { _ = pluginInterface?.pointee?.pointee.Release(smartInterface) }
defer {
if smartInterface != nil {
_ = pluginInterface?.pointee?.pointee.Release(smartInterface)
}
}
guard result == KERN_SUCCESS, let smart = smartInterface?.pointee else { return nil }
var smartData: nvme_smart_log = nvme_smart_log()

View File

@@ -17,7 +17,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>474</string>
<string>476</string>
<key>Description</key>
<string>Simple macOS system monitor in your menu bar</string>
<key>LSApplicationCategoryType</key>