Post

Replies

Boosts

Views

Activity

Security Framework: unreleased memory
I'm writing software that uses the security framework to get signing information from applications. I noticed that over time memory consumption goes up. After checking with Instruments, I saw an accumulation of objects coming from the internals of the security framework. These allocated objects don't seem to go away. Following is a standalone code sample that seems to cause the problem in my env. Running it by itself creates a big number of objects that are not released. I also attached a screenshot from Instruments. #include <Foundation/Foundation.h> #include <Security/Security.h> #include <unistd.h> OSStatus get_signing_info(const char* path) { SecStaticCodeRef codeRef = NULL; OSStatus status; NSString* str = [NSString stringWithUTF8String:path]; NSURL* url = [NSURL fileURLWithPath:str]; status = SecStaticCodeCreateWithPath((__bridge CFURLRef)url, kSecCSDefaultFlags, &codeRef); CFDictionaryRef _info = NULL; status = SecCodeCopySigningInformation(codeRef, kSecCSSigningInformation, &_info); NSDictionary* info = (__bridge_transfer NSDictionary *)_info; int flags = [[info objectForKey:(NSString *)kSecCodeInfoFlags] intValue]; NSLog(@"%d", flags); CFRelease(codeRef); return status; } int main(int argc, const char * argv[]) { @autoreleasepool { for (int i = 0; i < 1000; ++i) { @autoreleasepool { OSStatus status = get_signing_info(argv[1]); NSLog(@"i=%d, status=%d", i, status); } } sleep(100); } return 0; } Is there a way to get rid of these objects that clog up the memory? Or perhaps use the framework differently to avoid this issue?
1
0
385
Aug ’24