diff --git a/ActiveSync/NSData+ActiveSync.m b/ActiveSync/NSData+ActiveSync.m index abd91995a..34fa4da95 100644 --- a/ActiveSync/NSData+ActiveSync.m +++ b/ActiveSync/NSData+ActiveSync.m @@ -86,15 +86,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. return nil; } - data = [[NSData alloc] initWithBytes: xml length: xml_len]; + data = [NSData dataWithBytesNoCopy: xml length: xml_len freeWhenDone: YES]; #if WBXMLDEBUG [data writeToFile: @"/tmp/protocol.decoded" atomically: YES]; #endif - free(xml); - - return AUTORELEASE(data); + return data; } @@ -138,15 +136,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. return nil; } - data = [[NSData alloc] initWithBytes: wbxml length: wbxml_len]; + data = [NSData dataWithBytesNoCopy: wbxml length: wbxml_len freeWhenDone: YES]; #if WBXMLDEBUG [data writeToFile: @"/tmp/protocol.encoded" atomically: YES]; #endif - free(wbxml); wbxml_conv_xml2wbxml_destroy(conv); - - return AUTORELEASE(data); + + return data; } @end diff --git a/ActiveSync/SOGoActiveSyncDispatcher+Sync.m b/ActiveSync/SOGoActiveSyncDispatcher+Sync.m index 5690fea08..bb2f67d4e 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher+Sync.m +++ b/ActiveSync/SOGoActiveSyncDispatcher+Sync.m @@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #import "SOGoActiveSyncDispatcher+Sync.h" #import +#import #import #import #import @@ -114,22 +115,25 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. forKey: (NSString *) theFolderKey { SOGoCacheGCSObject *o; + NSDictionary *values; NSString *key; key = [NSString stringWithFormat: @"%@+%@", [context objectForKey: @"DeviceId"], theFolderKey]; - + values = [theFolderMetadata copy]; + o = [SOGoCacheGCSObject objectWithName: key inContainer: nil]; [o setObjectType: ActiveSyncFolderCacheObject]; [o setTableUrl: [self folderTableURL]]; - [o reloadIfNeeded]; + //[o reloadIfNeeded]; [[o properties] removeObjectForKey: @"SyncKey"]; [[o properties] removeObjectForKey: @"SyncCache"]; [[o properties] removeObjectForKey: @"DateCache"]; [[o properties] removeObjectForKey: @"MoreAvailable"]; - [[o properties] addEntriesFromDictionary: theFolderMetadata]; + [[o properties] addEntriesFromDictionary: values]; [o save]; + [values release]; } - (NSMutableDictionary *) _folderMetadataForKey: (NSString *) theFolderKey @@ -534,6 +538,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. { NSMutableDictionary *folderMetadata, *dateCache, *syncCache; + NSAutoreleasePool *pool; NSMutableString *s; BOOL more_available; @@ -635,6 +640,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. allComponents = [theCollection syncTokenFieldsWithProperties: nil matchingSyncToken: theSyncKey fromDate: theFilterType]; allComponents = [allComponents sortedArrayUsingDescriptors: [NSArray arrayWithObjects: [[NSSortDescriptor alloc] initWithKey: @"c_lastmodified" ascending:YES], nil]]; + // Check for the WindowSize max = [allComponents count]; @@ -643,14 +649,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. for (i = 0; i < max; i++) { + pool = [[NSAutoreleasePool alloc] init]; + // Check for the WindowSize and slice accordingly if (return_count >= theWindowSize) { more_available = YES; // -1 to make sure that we miss no event in case there are more with the same c_lastmodified - *theLastServerKey = [NSString stringWithFormat: @"%d", [[component objectForKey: @"c_lastmodified"] intValue] - 1]; + *theLastServerKey = [[NSString alloc] initWithFormat: @"%d", [[component objectForKey: @"c_lastmodified"] intValue] - 1]; + DESTROY(pool); break; } @@ -747,6 +756,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [s appendString: @""]; return_count++; + + DESTROY(pool); } } // for ... @@ -763,6 +774,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [self _setFolderMetadata: folderMetadata forKey: [NSString stringWithFormat: @"%@/%@", component_name, [theCollection nameInContainer]]]; + + RELEASE(*theLastServerKey); } break; case ActiveSyncMailFolder: @@ -830,6 +843,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. for (; k < [allCacheObjects count]; k++) { + pool = [[NSAutoreleasePool alloc] init]; + // Check for the WindowSize and slice accordingly if (return_count >= theWindowSize) { @@ -837,8 +852,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. more_available = YES; lastSequence = ([[aCacheObject sequence] isEqual: [NSNull null]] ? @"1" : [aCacheObject sequence]); - *theLastServerKey = [NSString stringWithFormat: @"%@-%@", [aCacheObject uid], lastSequence]; + *theLastServerKey = [[NSString alloc] initWithFormat: @"%@-%@", [aCacheObject uid], lastSequence]; //NSLog(@"Reached windowSize - lastUID will be: %@", *theLastServerKey); + DESTROY(pool); break; } @@ -919,7 +935,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. } } - } + DESTROY(pool); + } // for (; k < ...) if (more_available) { @@ -933,6 +950,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. } [self _setFolderMetadata: folderMetadata forKey: [self _getNameInCache: theCollection withType: theFolderType]]; + RELEASE(*theLastServerKey); + } // default: break; } // switch (folderType) ... @@ -1119,11 +1138,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [self processSyncGetChanges: theDocumentElement inCollection: collection withWindowSize: windowSize - //withWindowSize: 5 withSyncKey: syncKey withFolderType: folderType withFilterType: [NSCalendarDate dateFromFilterType: [[(id)[theDocumentElement getElementsByTagName: @"FilterType"] lastObject] textValue]] - //withFilterType: [NSCalendarDate dateFromFilterType: @"7"] inBuffer: changeBuffer lastServerKey: &lastServerKey]; } @@ -1310,7 +1327,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. BOOL changeDetected; // We initialize our output buffer - output = [NSMutableString string]; + output = [[NSMutableString alloc] init]; [output appendString: @""]; [output appendString: @""]; @@ -1366,8 +1383,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [output appendString: s]; [output appendString: @""]; - - d = [[output dataUsingEncoding: NSUTF8StringEncoding] xml2wbxml]; + + // Avoid overloading the autorelease pool here, as Sync command can + // generate fairly large responses. + d = [output dataUsingEncoding: NSUTF8StringEncoding]; + RELEASE(output); + + d = [d xml2wbxml]; [theResponse setContent: d]; } diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m index cc57836c8..5d1fd7da9 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher.m +++ b/ActiveSync/SOGoActiveSyncDispatcher.m @@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SOGoActiveSyncDispatcher.h" #import +#import #import #import #import @@ -2329,21 +2330,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. context: (id) theContext { id documentElement; + NSAutoreleasePool *pool; id builder, dom; SEL aSelector; NSString *cmdName, *deviceId; NSData *d; + pool = [[NSAutoreleasePool alloc] init]; + ASSIGN(context, theContext); - + // Get the device ID, device type and "stash" them deviceId = [[theRequest uri] deviceId]; [context setObject: deviceId forKey: @"DeviceId"]; [context setObject: [[theRequest uri] deviceType] forKey: @"DeviceType"]; [context setObject: [[theRequest uri] attachmentName] forKey: @"AttachmentName"]; - cmdName = [[theRequest uri] command]; // We make sure our cache table exists @@ -2379,6 +2382,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. { d = [[theRequest content] wbxml2xml]; } + documentElement = nil; if (!d) @@ -2414,8 +2418,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [theResponse setHeader: @"Sync,SendMail,SmartForward,SmartReply,GetAttachment,GetHierarchy,CreateCollection,DeleteCollection,MoveCollection,FolderSync,FolderCreate,FolderDelete,FolderUpdate,MoveItems,GetItemEstimate,MeetingResponse,Search,Settings,Ping,ItemOperations,ResolveRecipients,ValidateCert" forKey: @"MS-ASProtocolCommands"]; [theResponse setHeader: @"2.0,2.1,2.5,12.0,12.1,14.0,14.1" forKey: @"MS-ASProtocolVersions"]; - RELEASE(context); - + RELEASE(context); + RELEASE(pool); + return nil; } diff --git a/ActiveSync/SOGoMailObject+ActiveSync.m b/ActiveSync/SOGoMailObject+ActiveSync.m index e111b9edb..85a1bb61e 100644 --- a/ActiveSync/SOGoMailObject+ActiveSync.m +++ b/ActiveSync/SOGoMailObject+ActiveSync.m @@ -30,7 +30,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SOGoMailObject+ActiveSync.h" #import -#import #import #import #import @@ -511,7 +510,6 @@ struct GlobalObjectId { // - (NSString *) activeSyncRepresentationInContext: (WOContext *) _context { - NSAutoreleasePool *pool; NSData *d, *globalObjId; NSArray *attachmentKeys; NSMutableString *s; @@ -704,10 +702,6 @@ struct GlobalObjectId { // Body - namespace 17 preferredBodyType = [[context objectForKey: @"BodyPreferenceType"] intValue]; - // Make use of a local pool here as _preferredBodyDataUsingType:nativeType: will consume - // a significant amout of RAM and file descriptors - pool = [[NSAutoreleasePool alloc] init]; - nativeBodyType = 1; d = [self _preferredBodyDataUsingType: preferredBodyType nativeType: &nativeBodyType]; @@ -747,9 +741,7 @@ struct GlobalObjectId { } [s appendString: @""]; } - - DESTROY(pool); - + // Attachments -namespace 16 attachmentKeys = [self fetchFileAttachmentKeys]; if ([attachmentKeys count]) diff --git a/NEWS b/NEWS index 6c4e3e58f..d23120a7c 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ Enhancements - Improved the SAML2 documentation + - Radically reduced AES memory usage Bug fixes - Now possible to specify the username attribute for SAML2 (SOGoSAML2LoginAttribute) (#2381) diff --git a/SoObjects/SOGo/SOGoCacheGCSObject.m b/SoObjects/SOGo/SOGoCacheGCSObject.m index 1f83f8ed2..a2251173a 100644 --- a/SoObjects/SOGo/SOGoCacheGCSObject.m +++ b/SoObjects/SOGo/SOGoCacheGCSObject.m @@ -36,6 +36,7 @@ #import #import #import +#import #import #import #import @@ -96,10 +97,29 @@ static EOAttribute *textColumn = nil; - (void) dealloc { + //NSLog(@"SOGoCacheGCSObject: -dealloc for name: %@", nameInContainer); [tableUrl release]; [super dealloc]; } ++ (id) objectWithName: (NSString *) key inContainer: (id) theContainer +{ + SOGoCache *cache; + id o; + + cache = [SOGoCache sharedCache]; + o = [cache objectNamed: key inContainer: theContainer]; + + if (!o) + { + o = [super objectWithName: key inContainer: theContainer]; + //NSLog(@"Caching object with key: %@", key); + [cache registerObject: o withName: key inContainer: theContainer]; + } + + return o; +} + - (void) setTableUrl: (NSURL *) newTableUrl { ASSIGN (tableUrl, newTableUrl);