Permalink
Browse files

Fix an overrelease, a leak, and convert tabs to spaces

  • Loading branch information...
Zach Drayer
Zach Drayer committed Aug 27, 2012
1 parent fa237fc commit 6a18a1650980dfb93e2f391d16d4994ee06145c2
Showing with 52 additions and 50 deletions.
  1. +8 −6 Source/Main/XCGroup.m
  2. +44 −44 Source/Main/XCProject.m
View
@@ -431,12 +431,14 @@ - (NSString*) displayName {
- (NSString*) pathRelativeToProjectRoot {
if (_pathRelativeToProjectRoot == nil) {
NSMutableArray* pathComponents = [[NSMutableArray alloc] init];
- XCGroup* group;
+ XCGroup* group = nil;
NSString* key = [_key copy];
while ((group = [_project groupForGroupMemberWithKey:key]) != nil && !([group pathRelativeToParent] == nil)) {
[pathComponents addObject:[group pathRelativeToParent]];
- key = [group key];
+ id old = key;
+ key = [[group key] copy];
+ [old release];
}
NSMutableString* fullPath = [[NSMutableString alloc] init];
@@ -445,9 +447,9 @@ - (NSString*) pathRelativeToProjectRoot {
}
_pathRelativeToProjectRoot = [[fullPath stringByAppendingPathComponent:_pathRelativeToParent] copy];
- [fullPath release];
- [pathComponents release];
- [key release];
+ [fullPath release];
+ [pathComponents release];
+ [key release];
}
return _pathRelativeToProjectRoot;
}
@@ -472,7 +474,7 @@ - (void) addMemberWithKey:(NSString*)key {
}
- (void) flagMembersAsDirty {
- [_members release];
+ [_members release];
_members = nil;
}
View
@@ -52,7 +52,7 @@ - (id) initWithFilePath:(NSString*)filePath {
if (!_dataStore) {
[NSException raise:NSInvalidArgumentException format:@"Project file not found at file path %@", _filePath];
}
-
+
_fileOperationQueue =
[[XCFileOperationQueue alloc] initWithBaseDirectory:[_filePath stringByDeletingLastPathComponent]];
@@ -63,15 +63,15 @@ - (id) initWithFilePath:(NSString*)filePath {
/* ================================================== Deallocation ================================================== */
- (void) dealloc {
- [_filePath release];
- [_fileOperationQueue release];
- [_dataStore release];
- [_targets release];
- [_groups release];
- [_rootObjectKey release];
- [_defaultConfigurationName release];
-
- [super dealloc];
+ [_filePath release];
+ [_fileOperationQueue release];
+ [_dataStore release];
+ [_targets release];
+ [_groups release];
+ [_rootObjectKey release];
+ [_defaultConfigurationName release];
+
+ [super dealloc];
}
/* ================================================ Interface Methods =============================================== */
@@ -171,35 +171,35 @@ - (XCGroup*) rootGroup {
}
- (NSArray*) rootGroups {
- XCGroup *group = [self rootGroup];
- if (group) {
- return [NSArray arrayWithObject:group];
- }
+ XCGroup *group = [self rootGroup];
+ if (group) {
+ return [NSArray arrayWithObject:group];
+ }
- NSMutableArray *results = [NSMutableArray array];
+ NSMutableArray *results = [NSMutableArray array];
for (XCGroup* group in [self groups]) {
if ([group parentGroup] == nil) {
[results addObject:group];
}
}
- return [[results copy] autorelease];
+ return [[results copy] autorelease];
}
- (XCGroup*) groupWithKey:(NSString*)key {
- XCGroup *group = [_groups objectForKey:key];
- if (group)
- return [[group retain] autorelease];
+ XCGroup *group = [_groups objectForKey:key];
+ if (group)
+ return [[group retain] autorelease];
- NSDictionary* obj = [[self objects] valueForKey:key];
+ NSDictionary* obj = [[self objects] objectForKey:key];
if (obj && [[obj valueForKey:@"isa"] asMemberType] == PBXGroup) {
NSString* name = [obj valueForKey:@"name"];
NSString* path = [obj valueForKey:@"path"];
NSArray* children = [obj valueForKey:@"children"];
XCGroup *group = [XCGroup groupWithProject:self key:key alias:name path:path children:children];
- [_groups setObject:group forKey:key];
+ [_groups setObject:group forKey:key];
return group;
}
@@ -209,21 +209,21 @@ - (XCGroup*) groupWithKey:(NSString*)key {
- (XCGroup*) groupForGroupMemberWithKey:(NSString*)key {
for (XCGroup* group in [self groups]) {
if ([group memberWithKey:key]) {
- return group;
+ return [[group retain] autorelease];
}
}
return nil;
}
- (XCGroup*) groupWithSourceFile:(XCSourceFile*)sourceFile {
- for (XCGroup *group in [self groups]) {
- for (id<XcodeGroupMember> member in [group members]) {
- if ([member isKindOfClass:[XCSourceFile class]] && [[sourceFile key] isEqualToString:[member key]]) {
- return group;
- }
- }
- }
- return nil;
+ for (XCGroup *group in [self groups]) {
+ for (id<XcodeGroupMember> member in [group members]) {
+ if ([member isKindOfClass:[XCSourceFile class]] && [[sourceFile key] isEqualToString:[member key]]) {
+ return group;
+ }
+ }
+ }
+ return nil;
}
//TODO: This could fail if the path attribute on a given group is more than one directory. Start with candidates and
//TODO: search backwards.
@@ -281,33 +281,33 @@ - (NSMutableDictionary*) objects {
- (NSDictionary*) configurations {
- if (_configurations == nil) {
- NSString *buildConfigurationRootSectionKey = [[[self objects] objectForKey:[self rootObjectKey]] objectForKey:@"buildConfigurationList"];
- NSDictionary *buildConfigurationDictionary = [[self objects] objectForKey:buildConfigurationRootSectionKey];
- _configurations = [[XCBuildConfigurationList buildConfigurationsFromDictionary:[buildConfigurationDictionary objectForKey:@"buildConfigurations"] inProject:self] mutableCopy];
- _defaultConfigurationName = [[buildConfigurationDictionary objectForKey:@"defaultConfigurationName"] copy];
- }
-
- return [[_configurations copy] autorelease];
+ if (_configurations == nil) {
+ NSString *buildConfigurationRootSectionKey = [[[self objects] objectForKey:[self rootObjectKey]] objectForKey:@"buildConfigurationList"];
+ NSDictionary *buildConfigurationDictionary = [[self objects] objectForKey:buildConfigurationRootSectionKey];
+ _configurations = [[XCBuildConfigurationList buildConfigurationsFromDictionary:[buildConfigurationDictionary objectForKey:@"buildConfigurations"] inProject:self] mutableCopy];
+ _defaultConfigurationName = [[buildConfigurationDictionary objectForKey:@"defaultConfigurationName"] copy];
+ }
+
+ return [[_configurations copy] autorelease];
}
- (NSDictionary*) configurationWithName:(NSString*)name {
- return [[self configurations] objectForKey:name];
+ return [[self configurations] objectForKey:name];
}
- (XCBuildConfigurationList*)defaultConfiguration {
- return [[self configurations] objectForKey:_defaultConfigurationName];
+ return [[self configurations] objectForKey:_defaultConfigurationName];
}
/* ================================================== Private Methods =============================================== */
#pragma mark Private
- (NSString*) rootObjectKey {
- if (_rootObjectKey == nil) {
- _rootObjectKey = [[_dataStore objectForKey:@"rootObject"] copy];;
- }
+ if (_rootObjectKey == nil) {
+ _rootObjectKey = [[_dataStore objectForKey:@"rootObject"] copy];;
+ }
- return _rootObjectKey;
+ return _rootObjectKey;
}
- (NSArray*) projectFilesOfType:(XcodeSourceFileType)projectFileType {

0 comments on commit 6a18a16

Please sign in to comment.