Ignore:
Timestamp:
May 14, 2013, 4:26:09 PM (6 years ago)
Author:
landonf@…
Message:

Be more aggressive with retaining/releasing autorelease pools as to keep memory usage at an absolute minimum.

Location:
trunk/dports/security/certsync
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/dports/security/certsync/Portfile

    r106070 r106085  
    33PortSystem 1.0
    44name                    certsync
    5 version                 1.0.2
     5version                 1.0.3
    66categories              security
    77conflicts               curl-ca-bundle
  • trunk/dports/security/certsync/files/certsync.m

    r106042 r106085  
    129129        /* Lookup failed */
    130130        if (outError != NULL)
    131             *outError = [NSError errorWithDomain: NSOSStatusErrorDomain code: err userInfo:nil];
    132        
    133         [pool release];
     131            *outError = [[NSError errorWithDomain: NSOSStatusErrorDomain code: err userInfo:nil] retain];
     132       
     133        [pool release];
     134        [*outError autorelease];
    134135        return nil;
    135136    }
     
    291292static void certsync_keychain_cb (ConstFSEventStreamRef streamRef, void *clientCallBackInfo, size_t numEvents, void *eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[])
    292293{
     294    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     295
    293296    MPCertSyncConfig *config = (MPCertSyncConfig *) clientCallBackInfo;
    294297
     
    296299    if ((ret = exportCertificates(config->userAnchors, config->outputFile)) != EXIT_SUCCESS)
    297300        exit(ret);
     301
     302    [pool release];
    298303}
    299304
     
    334339   
    335340    /* Perform single-shot export  */
    336     if (!runServer)
     341    if (NO && !runServer)
    337342        return exportCertificates(userAnchors, outputFile);
    338343   
    339344    /* Formulate the list of directories to observe; We use FSEvents rather than SecKeychainAddCallback(), as during testing the keychain
    340345     * API never actually fired a callback for the target keychains. */
    341     NSSearchPathDomainMask searchPathDomains = NSLocalDomainMask|NSSystemDomainMask;
    342     if (userAnchors)
    343         searchPathDomains |= NSUserDomainMask;
    344 
    345     NSArray *libraryDirectories = NSSearchPathForDirectoriesInDomains(NSAllLibrariesDirectory, searchPathDomains, YES);
    346     NSMutableArray *keychainDirectories = [NSMutableArray arrayWithCapacity: [libraryDirectories count]];
    347     for (NSString *dir in libraryDirectories) {
    348         [keychainDirectories addObject: [dir stringByAppendingPathComponent: @"Keychains"]];
    349         [keychainDirectories addObject: [dir stringByAppendingPathComponent: @"Security/Trust Settings"]];
    350     }
    351 
    352     /* Configure the listener */
    353346    FSEventStreamRef eventStream;
    354     MPCertSyncConfig *config = [[[MPCertSyncConfig alloc] init] autorelease];
    355     config->userAnchors = userAnchors;
    356     config->outputFile = [outputFile retain];
    357 
    358     FSEventStreamContext ctx = {
    359         .version = 0,
    360         .info = config,
    361         .retain = CFRetain,
    362         .release = CFRelease,
    363         .copyDescription = CFCopyDescription
    364     };
    365     eventStream = FSEventStreamCreate(NULL, certsync_keychain_cb, &ctx, (CFArrayRef)keychainDirectories, kFSEventStreamEventIdSinceNow, 0.0, kFSEventStreamCreateFlagUseCFTypes);
    366     FSEventStreamScheduleWithRunLoop(eventStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
    367     FSEventStreamStart(eventStream);
     347    {
     348        NSAutoreleasePool *streamPool = [[NSAutoreleasePool alloc] init];
     349
     350        NSSearchPathDomainMask searchPathDomains = NSLocalDomainMask|NSSystemDomainMask;
     351        if (userAnchors)
     352            searchPathDomains |= NSUserDomainMask;
     353
     354        NSArray *libraryDirectories = NSSearchPathForDirectoriesInDomains(NSAllLibrariesDirectory, searchPathDomains, YES);
     355        NSMutableArray *keychainDirectories = [NSMutableArray arrayWithCapacity: [libraryDirectories count]];
     356        for (NSString *dir in libraryDirectories) {
     357            [keychainDirectories addObject: [dir stringByAppendingPathComponent: @"Keychains"]];
     358            [keychainDirectories addObject: [dir stringByAppendingPathComponent: @"Security/Trust Settings"]];
     359        }
     360
     361        /* Configure the listener */
     362        MPCertSyncConfig *config = [[[MPCertSyncConfig alloc] init] autorelease];
     363        config->userAnchors = userAnchors;
     364        config->outputFile = [outputFile retain];
     365
     366        FSEventStreamContext ctx = {
     367            .version = 0,
     368            .info = config,
     369            .retain = CFRetain,
     370            .release = CFRelease,
     371            .copyDescription = CFCopyDescription
     372        };
     373        eventStream = FSEventStreamCreate(NULL, certsync_keychain_cb, &ctx, (CFArrayRef)keychainDirectories, kFSEventStreamEventIdSinceNow, 0.0, kFSEventStreamCreateFlagUseCFTypes);
     374        FSEventStreamScheduleWithRunLoop(eventStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
     375        FSEventStreamStart(eventStream);
     376       
     377        [streamPool release];
     378    }
    368379
    369380    /* Perform an initial one-shot export, and then run forever */
    370     int ret;
    371     if ((ret = exportCertificates(userAnchors, outputFile)) != EXIT_SUCCESS)
    372         return EXIT_FAILURE;
    373    
     381    {
     382    NSAutoreleasePool *shotPool = [[NSAutoreleasePool alloc] init];
     383        int ret;
     384        if ((ret = exportCertificates(userAnchors, outputFile)) != EXIT_SUCCESS)
     385            return EXIT_FAILURE;
     386        [shotPool release];
     387    }
     388
    374389    CFRunLoopRun();
    375 
    376390    FSEventStreamRelease(eventStream);
    377391    [pool release];
Note: See TracChangeset for help on using the changeset viewer.