Skip to content

Commit 1cbf2b5

Browse files
fix(device_info_plus): fix memory leak when calling DeviceInfoPlugin().macOsInfo (#3474)
Co-authored-by: Miguel Beltran <m@beltran.work>
1 parent f60d051 commit 1cbf2b5

File tree

1 file changed

+9
-16
lines changed
  • packages/device_info_plus/device_info_plus/macos/device_info_plus/Sources/device_info_plus

1 file changed

+9
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
import Foundation
22

3-
public struct SystemUUID {
4-
3+
public enum SystemUUID {
54
public static func getSystemUUID() -> String? {
6-
let dev = IOServiceMatching("IOPlatformExpertDevice")
7-
8-
var platformExpert: io_service_t
9-
if #available(macOS 12, *) {
10-
platformExpert = IOServiceGetMatchingService(kIOMainPortDefault, dev)
5+
let mainPort: mach_port_t
6+
if #available(macOS 12.0, *) {
7+
mainPort = kIOMainPortDefault
118
} else {
12-
platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, dev)
9+
mainPort = kIOMasterPortDefault
1310
}
14-
15-
let serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert, kIOPlatformUUIDKey as CFString, kCFAllocatorDefault, 0)
16-
IOObjectRelease(platformExpert)
17-
let ser: CFTypeRef? = serialNumberAsCFString?.takeUnretainedValue()
18-
if let result = ser as? String {
19-
return result
20-
}
21-
return nil
11+
let service = IOServiceGetMatchingService(mainPort, IOServiceMatching("IOPlatformExpertDevice"))
12+
let uuid = IORegistryEntryCreateCFProperty(service, kIOPlatformUUIDKey as CFString, kCFAllocatorDefault, 0).takeRetainedValue() as? String
13+
IOObjectRelease(service)
14+
return uuid
2215
}
2316
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy