Skip to content

Commit

Permalink
another attempt to fix a crasher, and more proof I don't really have …
Browse files Browse the repository at this point in the history
…a handle on memory management
  • Loading branch information
dustinrue committed Sep 5, 2012
1 parent 88b29fc commit fd93878
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
1 change: 0 additions & 1 deletion Source/ActiveApplicationEvidenceSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

@interface ActiveApplicationEvidenceSource : GenericEvidenceSource {
NSLock *lock;
NSMutableArray *applications;
}

@property (strong) NSString *activeApplication;
Expand Down
31 changes: 15 additions & 16 deletions Source/ActiveApplicationEvidenceSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ - (id)init
if (!(self = [super init]))
return nil;

applications = [[NSMutableArray alloc] init];
activeApplication = nil;

return self;
}

- (void)dealloc
{
[applications release];

[super dealloc];
}

- (void)doFullUpdate:(NSNotification *) notification {
NSRunningApplication *runningApplication = [[notification userInfo] objectForKey:@"NSWorkspaceApplicationKey"];

activeApplication = [runningApplication bundleIdentifier];

[lock lock];
activeApplication = [[[notification userInfo] objectForKey:@"NSWorkspaceApplicationKey"] bundleIdentifier];
[lock unlock];

DSLog(@"activeApplication %@ (%@)", activeApplication, [activeApplication class]);
// doFullUpdate is required, so just call it here
[self doFullUpdate];
}
Expand Down Expand Up @@ -76,7 +76,6 @@ - (void)stop
object:nil];

[lock lock];
[applications removeAllObjects];
[self setDataCollected:NO];
[lock unlock];

Expand All @@ -90,24 +89,19 @@ - (NSString *)name

- (BOOL)doesRuleMatch:(NSDictionary *)rule
{
[lock lock];
NSString *param = [rule valueForKey:@"parameter"];
BOOL match = NO;

if ([activeApplication class] == [NSArray class]) {
DSLog(@"weird, activeApplication is an array?");
return false;
}
NSString *localActiveApplication = [activeApplication copy];




NSString *localActiveApplication = [activeApplication copy];

if ([localActiveApplication isEqualToString:param]) {
match = YES;
}

[localActiveApplication release];

[lock unlock];
return match;
}

Expand Down Expand Up @@ -136,7 +130,7 @@ - (NSArray *)getSuggestions
}

[lock lock];
NSMutableArray *array = [NSMutableArray arrayWithCapacity:[applications count]];
NSMutableArray *array = [NSMutableArray arrayWithCapacity:[apps count]];

NSEnumerator *en = [apps objectEnumerator];
NSDictionary *dict;
Expand All @@ -159,4 +153,9 @@ - (NSString *) friendlyName {
return NSLocalizedString(@"Active Application", @"");
}

- (void) goingToSleep:(id)arg {
if (running)
activeApplication = nil;
}

@end

0 comments on commit fd93878

Please sign in to comment.