Skip to content

Commit

Permalink
remove a few static analyzer warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
cheekiatng committed Dec 5, 2016
1 parent b049813 commit 46e83b2
Show file tree
Hide file tree
Showing 29 changed files with 89 additions and 446 deletions.
421 changes: 20 additions & 401 deletions demos/KitchenSink/Resources/app.js

Large diffs are not rendered by default.

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
8 changes: 4 additions & 4 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 @@ -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 @@ -1052,9 +1052,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
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
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
6 changes: 5 additions & 1 deletion iphone/Classes/TiContactsGroup.m
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ -(void)add:(id)arg
subreason:nil
location:CODELOCATION];
};
//Ignore static analylzer warning here
RELEASE_TO_NIL(saveRequest)
return;
}
Expand Down Expand Up @@ -321,6 +322,7 @@ -(void)remove:(id)arg
subreason:nil
location:CODELOCATION];
};
//Ignore static analyzer warning here
RELEASE_TO_NIL(saveRequest)
return;
}
Expand All @@ -342,15 +344,17 @@ -(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
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
return saveRequest;
}

@end
#endif
#endif
4 changes: 4 additions & 0 deletions iphone/Classes/TiContactsPerson.m
Original file line number Diff line number Diff line change
Expand Up @@ -950,27 +950,31 @@ -(CNSaveRequest*)getSaveRequestForDeletion
{
CNSaveRequest *saveRequest = [[CNSaveRequest alloc] init];
[saveRequest deleteContact:person];
//Do not be tempted to autorelease here. https://github.com/appcelerator/titanium_mobile/pull/7464/files
return saveRequest;
}

-(CNSaveRequest*)getSaveRequestForAddition: (NSString*)containerIdentifier
{
CNSaveRequest *saveRequest = [[CNSaveRequest alloc] init];
[saveRequest addContact:person toContainerWithIdentifier:containerIdentifier];
//Do not be tempted to autorelease here. https://github.com/appcelerator/titanium_mobile/pull/7464/files
return saveRequest;
}

-(CNSaveRequest*)getSaveRequestForAddToGroup: (CNMutableGroup*) group
{
CNSaveRequest *saveRequest = [[CNSaveRequest alloc] init];
[saveRequest addMember:person toGroup:group];
//Do not be tempted to autorelease here. https://github.com/appcelerator/titanium_mobile/pull/7464/files
return saveRequest;
}

-(CNSaveRequest*)getSaveRequestForRemoveFromGroup: (CNMutableGroup*) group
{
CNSaveRequest *saveRequest = [[CNSaveRequest alloc] init];
[saveRequest removeMember:person fromGroup:group];
//Do not be tempted to autorelease here. https://github.com/appcelerator/titanium_mobile/pull/7464/files
return saveRequest;
}

Expand Down
4 changes: 2 additions & 2 deletions iphone/Classes/TiDataStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ -(id)init
return self;
}

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

#pragma mark I/O Stream implementation
Expand Down
1 change: 0 additions & 1 deletion iphone/Classes/TiLocale.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ +(NSString*)defaultLocale
NSArray* languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
NSString *preferredLang = [languages objectAtIndex:0];
[TiLocale setLocale:preferredLang];
NSString *var = [[UIDevice currentDevice] systemVersion];
if ([TiUtils isIOS9OrGreater]) {
//[TIMOB-19566]:Truncate the current locale for parity between iOS versions
[l setCurrentLocale:[[l currentLocale] substringToIndex:2]];
Expand Down
7 changes: 6 additions & 1 deletion iphone/Classes/TiNetworkSocketTCPProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ -(id)init

-(void)dealloc
{
RELEASE_TO_NIL(connected);
RELEASE_TO_NIL(error);
RELEASE_TO_NIL(closed);
RELEASE_TO_NIL(accepted);
RELEASE_TO_NIL(host);
// Calls _destroy
[super dealloc];
}
Expand Down Expand Up @@ -887,4 +892,4 @@ -(void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
}

@end
#endif
#endif
14 changes: 5 additions & 9 deletions iphone/Classes/TiPreviewingDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,16 @@ -(void)dealloc
{
[[[self previewContext] preview] forgetSelf];
[[[self previewContext] sourceView] forgetSelf];

RELEASE_TO_NIL(_previewContext);

RELEASE_TO_NIL(_listViewEvent);

RELEASE_TO_NIL(_previewContext);
[super dealloc];
}

-(void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit
{
NSMutableDictionary * propertiesDict = [[NSMutableDictionary alloc] initWithDictionary:[self listViewEvent]];
NSMutableDictionary * propertiesDict = [[[NSMutableDictionary alloc] initWithDictionary:[self listViewEvent]] autorelease];
[propertiesDict setObject:_previewContext.preview forKey:@"preview"];

NSArray * invocationArray = [[NSArray alloc] initWithObjects:&propertiesDict count:1];

[[self previewContext] fireEvent:@"pop" withObject:propertiesDict];
}

Expand All @@ -66,7 +62,7 @@ - (UIViewController*)previewingContext:(id<UIViewControllerPreviewing>)previewin
[[self previewContext] fireEvent:@"peek" withObject:@{@"preview": [[self previewContext] preview]}];
}

TiViewController *controller = [[TiViewController alloc] initWithViewProxy:[[self previewContext] preview]];
TiViewController *controller = [[[TiViewController alloc] initWithViewProxy:[[self previewContext] preview]] autorelease];
[[[[self previewContext] preview] view] setFrame:[[controller view] bounds]];
[[controller view] addSubview:[[[self previewContext] preview] view]];

Expand Down Expand Up @@ -157,7 +153,7 @@ -(NSDictionary*)receiveListViewEventFromIndexPath:(NSIndexPath*)indexPath
[eventObject setObject:itemId forKey:@"itemId"];
}

return eventObject;
return [eventObject autorelease];
}
#endif

Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/TiProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ -(void)dealloc
#if PROXY_MEMORY_TRACK == 1
NSLog(@"[DEBUG] DEALLOC: %@ (%d)",self,[self hash]);
#endif
RELEASE_TO_NIL(modelDelegate);
[self _destroy];
pthread_rwlock_destroy(&listenerLock);
pthread_rwlock_destroy(&dynpropsLock);
Expand Down
3 changes: 1 addition & 2 deletions iphone/Classes/TiUIEmailDialogProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ - (void)mailComposeController:(MFMailComposeViewController *)composer didFinishW

[[TiApp app] hideModalController:composer animated:animated];
[composer autorelease];
composer = nil;
if ([self _hasListeners:@"complete"])
{
NSDictionary *event = [NSDictionary dictionaryWithObject:NUMINT(result) forKey:@"result"];
Expand All @@ -182,4 +181,4 @@ - (void)mailComposeController:(MFMailComposeViewController *)composer didFinishW

@end

#endif
#endif
1 change: 0 additions & 1 deletion iphone/Classes/TiUITabGroup.m
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewCon
else
{
[self updateMoreBar:(UINavigationController *)viewController];
viewController = nil;
}

}
Expand Down
2 changes: 1 addition & 1 deletion iphone/Classes/TiUITextField.m
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ -(void)setHintTextColor_:(id)value
hintText = @"";
}

[(TiTextField*)[self textWidgetView] setAttributedPlaceholder:[[NSAttributedString alloc] initWithString:[TiUtils stringValue:hintText] attributes:@{NSForegroundColorAttributeName:[[TiUtils colorValue:value] _color]}]];
[(TiTextField*)[self textWidgetView] setAttributedPlaceholder:[[[NSAttributedString alloc] initWithString:[TiUtils stringValue:hintText] attributes:@{NSForegroundColorAttributeName:[[TiUtils colorValue:value] _color]}] autorelease]];
}

-(void)setAttributedHintText_:(id)value
Expand Down
3 changes: 2 additions & 1 deletion iphone/Classes/TiUIWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@ -(void)setData_:(id)args
{
[self ensureLocalProtocolHandler];
// Empty NSURL since nil is not accepted here
[[self webview] loadData:[blob data] MIMEType:[blob mimeType] textEncodingName:@"utf-8" baseURL:[NSURL new]];
NSURL *emptyURL = [[NSURL new] autorelease];
[[self webview] loadData:[blob data] MIMEType:[blob mimeType] textEncodingName:@"utf-8" baseURL:emptyURL];
if (scalingOverride==NO)
{
[[self webview] setScalesPageToFit:YES];
Expand Down
6 changes: 3 additions & 3 deletions iphone/Classes/TiUIiOSApplicationShortcutsProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ -(NSArray*)listStaticShortcuts:(id)unused
UIApplicationShortcutIcon *icon = [UIApplicationShortcutIcon iconWithType:[TiUtils intValue:[item valueForKey:@"UIApplicationShortcutItemIconType"]]];
NSDictionary *userInfo = [item valueForKey:@"UIApplicationShortcutItemUserInfo"];

UIApplicationShortcutItem *shortcut = [[UIApplicationShortcutItem alloc] initWithType:type
UIApplicationShortcutItem *shortcut = [[[UIApplicationShortcutItem alloc] initWithType:type
localizedTitle:title
localizedSubtitle:subtitle
icon:icon
userInfo:userInfo];
userInfo:userInfo] autorelease];

[shortcutsToReturn addObject:[self shortcutItemToDictionary:shortcut]];
}
Expand Down Expand Up @@ -240,4 +240,4 @@ -(NSString*)urlInAssetCatalog:(NSString*)url
}

@end
#endif
#endif
8 changes: 7 additions & 1 deletion iphone/Classes/TiUIiOSLivePhoto.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ -(instancetype)initWithLivePhoto:(PHLivePhoto*)livePhoto
return self;
}

@end
-(void)dealloc
{
RELEASE_TO_NIL(_livePhoto);
[super dealloc];
}

@end
3 changes: 2 additions & 1 deletion iphone/Classes/TiUIiOSMenuPopupProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ -(void)_initWithProperties:(NSDictionary *)properties
-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
RELEASE_TO_NIL(_menuItems);
[super dealloc];
}

Expand Down Expand Up @@ -100,4 +101,4 @@ -(void)registerNotificationCenter
}

@end
#endif
#endif
4 changes: 2 additions & 2 deletions iphone/Classes/TiUIiOSPreviewContextProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ -(void)connectToDelegate
}

UIViewController *controller = [[[TiApp app] controller] topPresentedController];
[controller registerForPreviewingWithDelegate:[[TiPreviewingDelegate alloc] initWithPreviewContext:self]
[controller registerForPreviewingWithDelegate:[[[TiPreviewingDelegate alloc] initWithPreviewContext:self] autorelease]
sourceView:nativeSourceView];
}

@end
#endif
#endif

0 comments on commit 46e83b2

Please sign in to comment.