Skip to content

Commit

Permalink
fix(device_info_plus): fix memory leak when calling DeviceInfoPlugin(…
Browse files Browse the repository at this point in the history
…).macOsInfo (#3474)

Co-authored-by: Miguel Beltran <[email protected]>
  • Loading branch information
codingiran and miquelbeltran authored Feb 20, 2025
1 parent f60d051 commit 1cbf2b5
Showing 1 changed file with 9 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import Foundation

public struct SystemUUID {

public enum SystemUUID {
public static func getSystemUUID() -> String? {
let dev = IOServiceMatching("IOPlatformExpertDevice")

var platformExpert: io_service_t
if #available(macOS 12, *) {
platformExpert = IOServiceGetMatchingService(kIOMainPortDefault, dev)
let mainPort: mach_port_t
if #available(macOS 12.0, *) {
mainPort = kIOMainPortDefault
} else {
platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, dev)
mainPort = kIOMasterPortDefault
}

let serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert, kIOPlatformUUIDKey as CFString, kCFAllocatorDefault, 0)
IOObjectRelease(platformExpert)
let ser: CFTypeRef? = serialNumberAsCFString?.takeUnretainedValue()
if let result = ser as? String {
return result
}
return nil
let service = IOServiceGetMatchingService(mainPort, IOServiceMatching("IOPlatformExpertDevice"))
let uuid = IORegistryEntryCreateCFProperty(service, kIOPlatformUUIDKey as CFString, kCFAllocatorDefault, 0).takeRetainedValue() as? String
IOObjectRelease(service)
return uuid
}
}

0 comments on commit 1cbf2b5

Please sign in to comment.