@@ -20,23 +20,22 @@ package collector
2020#cgo CFLAGS: -x objective-c
2121#cgo LDFLAGS: -framework Foundation
2222#import <Foundation/Foundation.h>
23- Float64 * purgeable(char *path) {
23+ Float64 purgeable(char *path) {
2424 CFNumberRef tmp;
25- Float64 *value;
2625 NSError *error = nil;
2726 NSString *str = [NSString stringWithUTF8String:path];
2827 NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:str];
2928 NSDictionary *results = [fileURL resourceValuesForKeys:@[NSURLVolumeAvailableCapacityForImportantUsageKey] error:&error];
3029 if (results) {
31- if ((tmp = CFDictionaryGetValue((CFDictionaryRef)results, NSURLVolumeAvailableCapacityForImportantUsageKey)) == NULL)
32- return NULL;
33- value = (Float64 *)malloc(sizeof(Float64));
34- if (CFNumberGetValue(tmp, kCFNumberFloat64Type, value)) {
30+ if ((tmp = CFDictionaryGetValue((CFDictionaryRef)results, NSURLVolumeAvailableCapacityForImportantUsageKey)) == NULL) {
31+ return -1.0f;
32+ }
33+ Float64 value;
34+ if (CFNumberGetValue(tmp, kCFNumberFloat64Type, &value)) {
3535 return value;
3636 }
3737 }
38- free(value);
39- return NULL;
38+ return -1.0f;
4039}
4140*/
4241import "C"
@@ -100,7 +99,7 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
10099 avail : float64 (mnt [i ].f_bavail ) * float64 (mnt [i ].f_bsize ),
101100 files : float64 (mnt [i ].f_files ),
102101 filesFree : float64 (mnt [i ].f_ffree ),
103- purgeable : ( * float64 ) (C .purgeable (C .CString (mountpoint ))),
102+ purgeable : float64 (C .purgeable (C .CString (mountpoint ))),
104103 ro : ro ,
105104 })
106105 }
0 commit comments