Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-23542] (6_0_X) iOS: Remove all memory leaks and analyzer warnings #8973

Merged
merged 5 commits into from
Apr 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions iphone/Classes/CalendarModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ -(void) eventStoreChanged:(NSNotification*)notification

-(void)dealloc
{
RELEASE_TO_NIL(store);
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
[store release];
[[NSNotificationCenter defaultCenter] removeObserver:self];

}

-(void)didReceiveMemoryWarning:(NSNotification*)notification
Expand Down
4 changes: 2 additions & 2 deletions iphone/Classes/FilesystemModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ -(id)getAsset:(id)args
RELEASE_TO_NIL(sha)
}
}
return [[TiBlob alloc] _initWithPageContext:[self executionContext] andImage:image];
return [[[TiBlob alloc] _initWithPageContext:[self executionContext] andImage:image] autorelease];
}
return [NSNull null];
}
Expand All @@ -252,4 +252,4 @@ -(NSString*)IOS_FILE_PROTECTION_COMPLETE_UNTIL_FIRST_USER_AUTHENTICATION

@end

#endif
#endif
4 changes: 2 additions & 2 deletions iphone/Classes/GeolocationModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ -(void)reverseGeocoder:(id)args
ENSURE_ARG_COUNT(args,3);
KrollCallback *callback = [args objectAtIndex:2];
ENSURE_TYPE(callback,KrollCallback);
#ifndef __clang_analyzer__ //ignore static analyzer error here, memory will be released
#ifndef __clang_analyzer__ // Ignore static analyzer error here, memory will be released. See TIMOB-19444
CGFloat lat = [TiUtils floatValue:[args objectAtIndex:0]];
CGFloat lon = [TiUtils floatValue:[args objectAtIndex:1]];
ReverseGeoCallback *rcb = [[ReverseGeoCallback alloc] initWithCallback:callback context:[self executionContext]];
Expand All @@ -548,7 +548,7 @@ -(void)forwardGeocoder:(id)args
ENSURE_ARG_COUNT(args,2);
KrollCallback *callback = [args objectAtIndex:1];
ENSURE_TYPE(callback,KrollCallback);
#ifndef __clang_analyzer__ //ignore static analyzer error here, memory will be released
#ifndef __clang_analyzer__ // Ignore static analyzer error here, memory will be released. See TIMOB-19444
ForwardGeoCallback *fcb = [[ForwardGeoCallback alloc] initWithCallback:callback context:[self executionContext]];
[self performGeo:@"f" address:[TiUtils stringValue:[args objectAtIndex:0]] callback:fcb];
#endif
Expand Down
14 changes: 7 additions & 7 deletions iphone/Classes/KrollBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ - (TiModule *)loadTopLevelNativeModule:(TiModule *)module withPath:(NSString *)p
return module;
}

NSString* contents = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSString* contents = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
KrollWrapper* wrapper = (id) [self loadJavascriptText:contents fromFile:path withContext:kroll];

// For right now, we need to mix any compiled JS on top of a compiled module, so that both components
Expand Down Expand Up @@ -904,7 +904,7 @@ - (TiModule *)loadCoreModule:(NSString *)path withContext:(KrollContext *)kroll
// nope, return nil so we can try to fall back to resource in user's app
return nil;
}
NSString* contents = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSString* contents = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
// This is an asset inside the native module. Load it like a "normal" common js file
return [self loadJavascriptText:contents fromFile:filepath withContext:kroll];
}
Expand All @@ -920,7 +920,7 @@ - (NSString *)loadFile:(NSString *)path

if (data != nil) {
[self setCurrentURL:[NSURL URLWithString:[path stringByDeletingLastPathComponent] relativeToURL:[[self host] baseURL]]];
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
return [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
}
return nil;
}
Expand Down Expand Up @@ -1099,19 +1099,19 @@ - (NSArray *)nodeModulesPaths:(NSString *)path
path = @"/";
}
// 1. let PARTS = path split(START)
NSArray* parts = [path componentsSeparatedByString:@"/"];
NSArray *parts = [path componentsSeparatedByString:@"/"];
// 2. let I = count of PARTS - 1
NSInteger i = [parts count] - 1;
// 3. let DIRS = []
NSMutableArray* dirs = [[NSMutableArray alloc] initWithCapacity:0];
NSMutableArray *dirs = [NSMutableArray arrayWithCapacity:0];
// 4. while I >= 0,
while (i >= 0) {
// a. if PARTS[I] = "node_modules" CONTINUE
if ([[parts objectAtIndex:i] isEqual: @"node_modules"]) {
continue;
}
// b. DIR = path join(PARTS[0 .. I] + "node_modules")
NSString* dir = [[[parts componentsJoinedByString:@"/"] substringFromIndex:1] stringByAppendingPathComponent:@"node_modules"];
NSString *dir = [[[parts componentsJoinedByString:@"/"] substringFromIndex:1] stringByAppendingPathComponent:@"node_modules"];
// c. DIRS = DIRS + DIR
[dirs addObject:dir];
// d. let I = I - 1
Expand Down Expand Up @@ -1302,8 +1302,8 @@ + (KrollBridge *)krollBridgeForThreadName:(NSString *)threadName;
CFSetGetValues(krollBridgeRegistry, (const void **)registryObjects);
for (int currentBridgeIndex = 0; currentBridgeIndex < bridgeCount; currentBridgeIndex++)
{
KrollBridge * currentBridge = registryObjects[currentBridgeIndex];
#ifdef TI_USE_KROLL_THREAD
KrollBridge * currentBridge = registryObjects[currentBridgeIndex];
if ([[[currentBridge krollContext] threadName] isEqualToString:threadName])
{
result = [[currentBridge retain] autorelease];
Expand Down
4 changes: 2 additions & 2 deletions iphone/Classes/MediaModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -1026,9 +1026,9 @@ -(void)requestPhotoGalleryPermissions:(id)arg
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
BOOL granted = (status == PHAuthorizationStatusAuthorized);
NSString *errorMessage = granted ? @"" : @"The user denied access to use the photo gallery.";
KrollEvent *invocationEvent = [[KrollEvent alloc] initWithCallback:callback
KrollEvent *invocationEvent = [[[KrollEvent alloc] initWithCallback:callback
eventObject:[TiUtils dictionaryWithCode:(granted ? 0 : 1) message:errorMessage]
thisObject:self];
thisObject:self] autorelease];
[[callback context] enqueue:invocationEvent];
}];
}, YES);
Expand Down
3 changes: 1 addition & 2 deletions iphone/Classes/TiAnimation.m
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ -(void)dealloc
RELEASE_TO_NIL(transition);
RELEASE_TO_NIL(callback);
RELEASE_TO_NIL(view);
RELEASE_TO_NIL(animatedView);
[animatedViewProxy release];
[animatedViewProxy release];
[super dealloc];
}

Expand Down
3 changes: 1 addition & 2 deletions iphone/Classes/TiApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -1177,8 +1177,7 @@ - (NSString*)systemUserAgent
NSString *currentLocaleIdentifier = [[NSLocale currentLocale] localeIdentifier];
NSString *currentDeviceInfo = [NSString stringWithFormat:@"%@/%@; %@; %@;",[currentDevice model],[currentDevice systemVersion],[currentDevice systemName],currentLocaleIdentifier];
NSString *kTitaniumUserAgentPrefix = [NSString stringWithFormat:@"%s%s%s %s%s","Appc","eler","ator","Tita","nium"];

return [[NSString stringWithFormat:@"%@/%s (%@)",kTitaniumUserAgentPrefix,TI_VERSION_STR,currentDeviceInfo] retain];
return [NSString stringWithFormat:@"%@/%s (%@)",kTitaniumUserAgentPrefix,TI_VERSION_STR,currentDeviceInfo];
}

- (NSString*)userAgent
Expand Down
6 changes: 4 additions & 2 deletions iphone/Classes/TiAppiOSProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ -(void)didReceiveApplicationShortcutNotification:(NSNotification*)info
}

[self fireEvent:@"shortcutitemclick" withObject:event];
RELEASE_TO_NIL(event);
}

-(void)didHandleURL:(NSNotification*)info
Expand Down Expand Up @@ -623,13 +624,14 @@ -(id)scheduleLocalNotification:(id)args
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(latitude, longitude);

if (!CLLocationCoordinate2DIsValid(center)) {
RELEASE_TO_NIL(localNotif);
NSLog(@"[WARN] The provided region is invalid, please check your `latitude` and `longitude`!");
return;
}

localNotif.region = [[CLCircularRegion alloc] initWithCenter:center
localNotif.region = [[[CLCircularRegion alloc] initWithCenter:center
radius:kCLDistanceFilterNone
identifier:identifier ? identifier : @"notification"];
identifier:identifier ? identifier : @"notification"] autorelease];

localNotif.regionTriggersOnce = regionTriggersOnce;
}
Expand Down
7 changes: 3 additions & 4 deletions iphone/Classes/TiAppiOSSearchQueryProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ - (void)dealloc

- (id)_initWithPageContext:(id<TiEvaluator>)context andArguments:(NSDictionary*)args
{
if (self == [super _initWithPageContext:context]) {
ENSURE_TYPE([args objectForKey:@"queryString"], NSString);
ENSURE_TYPE([args objectForKey:@"attributes"], NSArray);

ENSURE_TYPE([args objectForKey:@"queryString"], NSString);
ENSURE_TYPE([args objectForKey:@"attributes"], NSArray);
if (self = [super _initWithPageContext:context]) {
queryString = [[args objectForKey:@"queryString"] retain];
attributes = [[args objectForKey:@"attributes"] retain];
}
Expand Down
6 changes: 6 additions & 0 deletions iphone/Classes/TiAppiOSSearchableItemProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ -(id)initWithUniqueIdentifier:(NSString *)identifier
return self;
}

-(void)dealloc
{
RELEASE_TO_NIL(_item);
[super dealloc];
}

-(NSString*)apiName
{
return @"Ti.App.iOS.SearchableItem";
Expand Down
3 changes: 2 additions & 1 deletion iphone/Classes/TiAppiOSUserActivityProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ -(id)initWithOptions:(NSDictionary*)props

-(void)dealloc
{
if(_supported){
if (_supported) {
[self clean];
}
RELEASE_TO_NIL(_userActivity);
[super dealloc];
}

Expand Down
17 changes: 15 additions & 2 deletions iphone/Classes/TiContactsGroup.m
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ -(void)add:(id)arg
subreason:nil
location:CODELOCATION];
};
// Ignore static analylzer warning here
// This is to release the saverequest in TiContactsPerson.m line 965 in (CNSaveRequest*)getSaveRequestForAddition
#ifndef __clang_analyzer__
RELEASE_TO_NIL(saveRequest)
#endif
return;
}

Expand Down Expand Up @@ -321,7 +325,11 @@ -(void)remove:(id)arg
subreason:nil
location:CODELOCATION];
};
// Ignore static analyzer warning here
// This is to release the saverequest in TiContactsPerson.m line 956 in (CNSaveRequest*)getSaveRequestForDeletion
#ifndef __clang_analyzer__
RELEASE_TO_NIL(saveRequest)
#endif
return;
}

Expand All @@ -338,19 +346,24 @@ -(void)remove:(id)arg
}

//For iOS9 deleting contact
#ifndef __clang_analyzer__
-(CNSaveRequest*)getSaveRequestForDeletion
{
CNSaveRequest *saveRequest = [[CNSaveRequest alloc] init];
[saveRequest deleteGroup: [[group mutableCopy] autorelease]];
// Do not be tempted to autorelease here. https://github.com/appcelerator/titanium_mobile/commit/a0d4a50d51f1afe85f92cf9e0d2ce8cca08fcf2f
// It will be released in ContactsModule.m line 315 in (void)save
return saveRequest;
}

-(CNSaveRequest*)getSaveRequestForAddition: (NSString*)containerIdentifier
{
CNSaveRequest *saveRequest = [[CNSaveRequest alloc] init];
[saveRequest addGroup:group toContainerWithIdentifier:containerIdentifier];
// Do not be tempted to autorelease here. https://github.com/appcelerator/titanium_mobile/commit/a0d4a50d51f1afe85f92cf9e0d2ce8cca08fcf2f
// It will be released in ContactsModule.m line 315 in (void)save
return saveRequest;
}

#endif
@end
#endif
#endif