summaryrefslogtreecommitdiffstats
path: root/src/osx
diff options
context:
space:
mode:
authorJos Dehaes <jos.dehaes@gmail.com>2021-10-10 20:23:11 +0200
committerJos Dehaes <jos.dehaes@gmail.com>2021-10-10 20:23:11 +0200
commitd5cb24fbeb19ae57507e1715aa402b2dc33f9b6b (patch)
treef614787e27e6c837e0e0e48ce0007da53ed9f052 /src/osx
parent8fad5a61bee973c22f3a11fd7fee2c4e40390bbb (diff)
RAII
Diffstat (limited to 'src/osx')
-rw-r--r--src/osx/btop_collect.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/osx/btop_collect.cpp b/src/osx/btop_collect.cpp
index 7460fb9..bd6de26 100644
--- a/src/osx/btop_collect.cpp
+++ b/src/osx/btop_collect.cpp
@@ -516,6 +516,15 @@ namespace Mem {
return bool(val);
}
+ class IOObject {
+ public:
+ IOObject(string name, io_object_t obj) : name(name), object(obj) {}
+ virtual ~IOObject() { IOObjectRelease(object); }
+ private:
+ string name;
+ io_object_t &object;
+ };
+
void collect_disk(unordered_flat_map<string, disk_info> &disks, unordered_flat_map<string, string> &mapping) {
io_registry_entry_t drive;
io_iterator_t drive_list;
@@ -531,7 +540,9 @@ namespace Mem {
Logger::error("Error in IOServiceGetMatchingServices()");
return;
}
+ auto d = IOObject("drive list", drive_list); // dummy var so it gets destroyed
while ((drive = IOIteratorNext(drive_list)) != 0) {
+ auto dr = IOObject("drive", drive);
io_registry_entry_t volumeRef;
IORegistryEntryGetParentEntry(drive, kIOServicePlane, &volumeRef);
if (volumeRef) {
@@ -547,11 +558,7 @@ namespace Mem {
if (disks.contains(mountpoint)) {
auto& disk = disks.at(mountpoint);
CFDictionaryRef properties;
- if (IORegistryEntryCreateCFProperties(volumeRef, (CFMutableDictionaryRef *)&properties, kCFAllocatorDefault, 0)) {
- Logger::error("Error in IORegistryEntryCreateCFProperties()");
- goto RETURN; // We must use a goto here to clean up drive_list
- }
-
+ IORegistryEntryCreateCFProperties(volumeRef, (CFMutableDictionaryRef *)&properties, kCFAllocatorDefault, 0);
if (properties) {
CFDictionaryRef statistics = (CFDictionaryRef)CFDictionaryGetValue(properties, CFSTR("Statistics"));
if (statistics) {
@@ -588,12 +595,7 @@ namespace Mem {
}
}
}
- /* Release. */
- IOObjectRelease(drive);
}
- RETURN:
- /* Release. */
- IOObjectRelease(drive_list);
}
auto collect(const bool no_update) -> mem_info & {