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

Fix additional leaks in UIKit #1789

Merged
merged 3 commits into from
Jan 26, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Frameworks/UIKit/NSAttributedString+UIKitAdditions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ static void _initForHtmlSubtree(NSMutableAttributedString* self, NSDictionary* p
if (curNode->type == XML_TEXT_NODE) {
// If text, append to the string with the current set of attributes
// Note that libxml uses UTF8 as its internal encoding, so the decode below ought to be safe
NSAttributedString* appendString =
[[NSAttributedString alloc] initWithString:[NSString stringWithUTF8String:reinterpret_cast<char*>(curNode->content)]
attributes:parentAttributes];
StrongId<NSAttributedString> appendString;
appendString.attach([[NSAttributedString alloc] initWithString:[NSString stringWithUTF8String:reinterpret_cast<char*>(curNode->content)]
attributes:parentAttributes]);
[self appendAttributedString:appendString];

} else if (curNode->type == XML_ELEMENT_NODE) {
Expand Down Expand Up @@ -229,7 +229,8 @@ - (instancetype)initWithData:(NSData*)data
NSStringEncoding encoding =
static_cast<NSStringEncoding>((encodingNumber) ? [encodingNumber intValue] : [NSString defaultCStringEncoding]);
// Decode the data
NSString* stringData = [[NSString alloc] initWithData:data encoding:encoding];
StrongId<NSString> stringData;
stringData.attach([[NSString alloc] initWithData:data encoding:encoding]);

if (stringData) {
// Get NSDefaultAttributes from options
Expand Down
2 changes: 1 addition & 1 deletion Frameworks/UIKit/NSString+UIKitAdditions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ - (CGSize)_sizeWithAttributes:(NSDictionary<NSString*, id>*)attributes constrain

// Private helper that converts a UILineBreakMode -> NSParagraphStyle
static inline NSParagraphStyle* _paragraphStyleWithLineBreakMode(UILineBreakMode lineBreakMode) {
NSMutableParagraphStyle* ret = [NSMutableParagraphStyle new];
NSMutableParagraphStyle* ret = [[[NSMutableParagraphStyle alloc] init] autorelease];
ret.lineBreakMode = lineBreakMode;
return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions Frameworks/UIKit/UIAlertView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ - (BOOL)isVisible {
if (alertPriv->_cancelText != nil && alertPriv->_numButtons == 1 && alertPriv->_numberOfRows < 2) {
float buttonsWidth = 270.0f;
// Make side by side buttons
alertPriv->_cancelView = (createButton(
alertPriv->_cancelView.attach(createButton(
self, alertPriv->_cancelButtonIndex, alertPriv->_cancelText, boxWidth / 2.0f - buttonsWidth / 2.0f, curHeight, 130.0f));
[alertPriv->_cancelView sendControlEventsOnBack:UIControlEventTouchUpInside];

Expand Down Expand Up @@ -530,7 +530,7 @@ - (BOOL)isVisible {

if (alertPriv->_cancelText != nil) {
curHeight += 10.0f;
alertPriv->_cancelView = (createButton(
alertPriv->_cancelView.attach(createButton(
self, alertPriv->_cancelButtonIndex, alertPriv->_cancelText, boxWidth / 2.0f - 280.0f / 2.0f, curHeight, 280.0f));
[alertPriv->_cancelView sendControlEventsOnBack:UIControlEventTouchUpInside];

Expand Down
7 changes: 4 additions & 3 deletions Frameworks/UIKit/UIDatePicker.mm
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,13 @@ static void didSelectDate(UIDatePicker* self, int row, int component) {
// Check if the day is invalid
bool isInvalid = false;

NSDateComponents* componentsCheck = [NSDateComponents new];
StrongId<NSDateComponents> componentsCheck;
componentsCheck.attach([[NSDateComponents alloc] init]);
[componentsCheck setMonth:month];
[componentsCheck setYear:year];
[componentsCheck setHour:17];

NSDate* dateCheck = [calendar dateFromComponents:componentsCheck];
[componentsCheck release];

NSRange range;

Expand All @@ -348,7 +348,8 @@ static void didSelectDate(UIDatePicker* self, int row, int component) {
isInvalid = true;
}

NSDateComponents* components = [NSDateComponents new];
StrongId<NSDateComponents> components;
components.attach([[NSDateComponents alloc] init]);
[components setMonth:month];
[components setDay:day];
[components setYear:year];
Expand Down
1 change: 1 addition & 0 deletions Frameworks/UIKit/UIGridLayoutInfo.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//
//******************************************************************************

#import "AssertARCEnabled.h"
#import <UIKit/UIKit.h>
#import "UIGridLayoutInfo.h"
#import "UIGridLayoutSection.h"
Expand Down
1 change: 1 addition & 0 deletions Frameworks/UIKit/UIGridLayoutRow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//
//******************************************************************************

#import "AssertARCEnabled.h"
#import <UIKit/UIKit.h>
#import "UIGridLayoutRow.h"
#import "UIGridLayoutSection.h"
Expand Down
1 change: 1 addition & 0 deletions Frameworks/UIKit/UIGridLayoutSection.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//
//******************************************************************************

#import "AssertARCEnabled.h"
#import "UIGridLayoutSection.h"
#import "UIGridLayoutItem.h"
#import "UIGridLayoutRow.h"
Expand Down
10 changes: 5 additions & 5 deletions Frameworks/UIKit/UIPageViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ - (void)_scrollToNewViewController:(UIViewController*)controller
[[_pages objectAtIndex:i] removeFromSuperview];
}

_controllers = [NSMutableArray new];
_pages = [NSMutableArray new];
_controllers.attach([NSMutableArray new]);
_pages.attach([NSMutableArray new]);

[self _pushController:controller direction:UIPageViewControllerNavigationDirectionForward targetOffset:&targetOffset];

Expand Down Expand Up @@ -229,16 +229,16 @@ - (void)_resetToCurrent {

if (currentControllers) {
_controllers = [NSMutableArray arrayWithArray:currentControllers];
_pages = [NSMutableArray new];
_pages.attach([NSMutableArray new]);
for (int i = 0; i < [_controllers count]; i++) {
_UIPageViewPage* newPage = [[_UIPageViewPage alloc] initWithFrame:self.frame viewController:[_controllers objectAtIndex:i]];
[_pages addObject:newPage];
[self addSubview:newPage];
[newPage release];
}
} else {
_controllers = [NSMutableArray new];
_pages = [NSMutableArray new];
_controllers.attach([NSMutableArray new]);
_pages.attach([NSMutableArray new]);
}

[self _updateVisible];
Expand Down
2 changes: 1 addition & 1 deletion Frameworks/UIKit/UISearchBar.mm
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ - (instancetype)initWithCoder:(NSCoder*)coder {
_placeholder = [coder decodeObjectForKey:@"UIPlaceholder"];

if (scopeBarTitles) {
_scopeButtons = [[UISegmentedControl alloc] initWithItems:scopeBarTitles];
_scopeButtons.attach([[UISegmentedControl alloc] initWithItems:scopeBarTitles]);
[self addSubview:(id)_scopeButtons];

[_scopeButtons setSelectedSegmentIndex:0];
Expand Down
19 changes: 10 additions & 9 deletions Frameworks/UIKit/UITabBarController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ @implementation UITabMoreController
@Status Interoperable
*/
- (instancetype)init {
[super init];

id table = [UITabMoreTableView new];
if (self = [super init]) {
Copy link
Contributor

@jaredhms jaredhms Jan 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (self = [super init]) { [](start = 2, length = 28)

thanks for fixing this, too #Resolved

StrongId<UITabMoreTableView> table;
table.attach([[UITabMoreTableView alloc] init]);
[self pushViewController:table animated:FALSE];
}

[self pushViewController:table animated:FALSE];
return self;
}

Expand Down Expand Up @@ -86,7 +87,7 @@ - (instancetype)initWithCoder:(NSCoder*)coder {
if (_tabBar == nil) {
TraceVerbose(TAG, L"No tab!");
}
_moreNavigationController = [UITabMoreController new];
_moreNavigationController.attach([UITabMoreController new]);
[self setViewControllers:viewControllers];
priv->_wantsFullScreenLayout = TRUE;
_tabBarChanged = true;
Expand All @@ -101,11 +102,11 @@ - (instancetype)initWithNibName:(NSString*)name bundle:(NSBundle*)bundle {
_selectedIndex = -1;

CGRect frame = { 0.0f, 0.0f, DisplayProperties::ScreenWidth(), 50.0f };
_tabBar = [[UITabBar alloc] initWithFrame:frame];
_tabBar.attach([[UITabBar alloc] initWithFrame:frame]);
[_tabBar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
[_tabBar setDelegate:self];
priv->_wantsFullScreenLayout = TRUE;
_moreNavigationController = [UITabMoreController new];
_moreNavigationController.attach([UITabMoreController new]);
_tabBarChanged = true;

return [super initWithNibName:name bundle:bundle];
Expand All @@ -115,7 +116,7 @@ - (instancetype)initWithNibName:(NSString*)name bundle:(NSBundle*)bundle {
@Status Interoperable
*/
- (void)setViewControllers:(NSArray*)controllers {
_viewControllers = [controllers copy];
_viewControllers.attach([controllers copy]);

// Setup tabs
NSMutableArray* tabItems = [NSMutableArray array];
Expand Down Expand Up @@ -234,7 +235,7 @@ - (void)setSelectedViewController:(UIViewController*)controller {
*/
- (void)loadView {
if (_moreNavigationController == nil) {
_moreNavigationController = [UITabMoreController new];
_moreNavigationController.attach([UITabMoreController new]);
}
if ([self nibName] != nil) {
[super loadView];
Expand Down
4 changes: 2 additions & 2 deletions Frameworks/UIKit/UITextView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ - (instancetype)initWithCoder:(NSCoder*)coder {
_layoutManager = [NSLayoutManager new];
[_layoutManager addTextContainer:_textContainer];
_layoutManager.delegate = self;
_layoutManager.textStorage = [NSTextStorage new];
_layoutManager.textStorage = [[NSTextStorage new] autorelease];

_textColor = [coder decodeObjectForKey:@"UITextColor"];
if (_textColor == nil) {
Expand Down Expand Up @@ -150,7 +150,7 @@ - (instancetype)initWithFrame:(CGRect)frame {
_layoutManager = [NSLayoutManager new];
[_layoutManager addTextContainer:_textContainer];
_layoutManager.delegate = self;
_layoutManager.textStorage = [NSTextStorage new];
_layoutManager.textStorage = [[NSTextStorage new] autorelease];

_alignment = UITextAlignmentLeft;
_font = [UIFont defaultFont];
Expand Down
14 changes: 10 additions & 4 deletions build/UIKit/lib/UIKitLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@
<ClangCompile Include="$(MSBuildThisFileDirectory)..\..\..\Frameworks\UIKit\UICollectionViewCell.mm">
<ObjectiveCARC>true</ObjectiveCARC>
</ClangCompile>
<ClangCompile Include="$(MSBuildThisFileDirectory)..\..\..\Frameworks\UIKit\UIGridLayoutSection.mm" />
<ClangCompile Include="$(MSBuildThisFileDirectory)..\..\..\Frameworks\UIKit\UIGridLayoutSection.mm">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IGridLayoutSection.mm" [](start = 81, length = 22)

Mind adding #import "AssertARCEnabled.h" to the tops of these files? It ensures we never accidentally turn ARC back off...

<ObjectiveCARC>true</ObjectiveCARC>
</ClangCompile>
<ClangCompile Include="$(MSBuildThisFileDirectory)..\..\..\Frameworks\UIKit\UICollectionViewController.mm">
<ObjectiveCARC>true</ObjectiveCARC>
</ClangCompile>
Expand All @@ -156,15 +158,19 @@
<ClangCompile Include="$(MSBuildThisFileDirectory)..\..\..\Frameworks\UIKit\UICollectionViewData.mm">
<ObjectiveCARC>true</ObjectiveCARC>
</ClangCompile>
<ClangCompile Include="$(MSBuildThisFileDirectory)..\..\..\Frameworks\UIKit\UIGridLayoutRow.mm" />
<ClangCompile Include="$(MSBuildThisFileDirectory)..\..\..\Frameworks\UIKit\UIGridLayoutRow.mm">
<ObjectiveCARC>true</ObjectiveCARC>
</ClangCompile>
<ClangCompile Include="$(MSBuildThisFileDirectory)..\..\..\Frameworks\UIKit\UICollectionViewLayout.mm">
<ObjectiveCARC>true</ObjectiveCARC>
</ClangCompile>
<ClangCompile Include="$(MSBuildThisFileDirectory)..\..\..\Frameworks\UIKit\UIGridLayoutItem.mm" />
<ClangCompile Include="$(MSBuildThisFileDirectory)..\..\..\Frameworks\UIKit\UICollectionViewUpdateItem.mm">
<ObjectiveCARC>true</ObjectiveCARC>
</ClangCompile>
<ClangCompile Include="$(MSBuildThisFileDirectory)..\..\..\Frameworks\UIKit\UIGridLayoutInfo.mm" />
<ClangCompile Include="$(MSBuildThisFileDirectory)..\..\..\Frameworks\UIKit\UIGridLayoutInfo.mm">
<ObjectiveCARC>true</ObjectiveCARC>
</ClangCompile>
<ClangCompile Include="$(MSBuildThisFileDirectory)..\..\..\Frameworks\UIKit\UrlLauncher.mm" />
<ClangCompile Include="$(MSBuildThisFileDirectory)..\..\..\Frameworks\UIKit\NSLayoutManager.mm" />
<ClangCompile Include="$(MSBuildThisFileDirectory)..\..\..\Frameworks\UIKit\NSParagraphStyle.mm" />
Expand Down Expand Up @@ -457,4 +463,4 @@
<ImportGroup Label="ExtensionTargets">
<Import Project="$(StarboardBasePath)\msvc\sdk-build.targets" />
</ImportGroup>
</Project>
</Project>