Skip to content

Commit

Permalink
fixed autorelease pool problem with memory
Browse files Browse the repository at this point in the history
  • Loading branch information
unixpickle committed Jan 3, 2014
1 parent 159b630 commit 9780b1c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 40 deletions.
4 changes: 2 additions & 2 deletions JamWiFi.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@
INFOPLIST_FILE = "JamWiFi/JamWiFi-Info.plist";
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx10.7;
SDKROOT = macosx;
WRAPPER_EXTENSION = app;
};
name = Debug;
Expand All @@ -406,7 +406,7 @@
INFOPLIST_FILE = "JamWiFi/JamWiFi-Info.plist";
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx10.7;
SDKROOT = macosx;
WRAPPER_EXTENSION = app;
};
name = Release;
Expand Down
2 changes: 1 addition & 1 deletion JamWiFi/ANListView.m
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ - (void)tableViewSelectionDidChange:(NSNotification *)notification {
- (NSString *)securityTypeString:(CWNetwork *)network {
if ([network supportsSecurity:kCWSecurityDynamicWEP]) {
return @"WEP";
} else if ([network supportsSecurity:kCWSecurityModeOpen]) {
} else if ([network supportsSecurity:kCWSecurityNone]) {
return @"Open";
} else if ([network supportsSecurity:kCWSecurityEnterprise]) {
return @"Enterprise";
Expand Down
1 change: 1 addition & 0 deletions JamWiFi/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import <Security/Authorization.h>

int main(int argc, char *argv[]) {

@autoreleasepool {
if (geteuid()) {
OSStatus myStatus;
Expand Down
76 changes: 39 additions & 37 deletions Wireless/ANWiFiSniffer.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,47 +71,49 @@ - (void)backgroundThread {
}
AN80211Packet * packet = nil;
while (true) {
if ([[NSThread currentThread] isCancelled]) {
[interface closeInterface];
interface = nil;
return;
}
[channelLock lock];
if (hopChannel) {
[[interface interface] setWLANChannel:hopChannel error:nil];
hopChannel = nil;
}
[channelLock unlock];
@try {
packet = [interface nextPacket:NO];
} @catch (NSException *exception) {
[self informDelegateError:[NSError errorWithDomain:@"pcap_next_ex" code:1 userInfo:nil]];
[interface closeInterface];
interface = nil;
return;
}
if ([[NSThread currentThread] isCancelled]) {
[interface closeInterface];
interface = nil;
return;
}
if (packet) [self informDelegatePacket:packet];
AN80211Packet * wPacket = nil;
@synchronized (writeBuffer) {
if ([writeBuffer count] > 0) {
wPacket = [writeBuffer objectAtIndex:0];
[writeBuffer removeObjectAtIndex:0];
@autoreleasepool {
if ([[NSThread currentThread] isCancelled]) {
[interface closeInterface];
interface = nil;
return;
}
}
if (wPacket) {
if (![interface writePacket:wPacket]) {
[self informDelegateError:[NSError errorWithDomain:@"pcap_inject" code:1 userInfo:nil]];
[channelLock lock];
if (hopChannel) {
[[interface interface] setWLANChannel:hopChannel error:nil];
hopChannel = nil;
}
[channelLock unlock];
@try {
packet = [interface nextPacket:NO];
} @catch (NSException * exception) {
[self informDelegateError:[NSError errorWithDomain:@"pcap_next_ex" code:1 userInfo:nil]];
[interface closeInterface];
interface = nil;
return;
}
}
if (!packet && !wPacket) {
usleep(5000); // sleep for 5 milliseconds
if ([[NSThread currentThread] isCancelled]) {
[interface closeInterface];
interface = nil;
return;
}
if (packet) [self informDelegatePacket:packet];
AN80211Packet * wPacket = nil;
@synchronized (writeBuffer) {
if ([writeBuffer count] > 0) {
wPacket = [writeBuffer objectAtIndex:0];
[writeBuffer removeObjectAtIndex:0];
}
}
if (wPacket) {
if (![interface writePacket:wPacket]) {
[self informDelegateError:[NSError errorWithDomain:@"pcap_inject" code:1 userInfo:nil]];
interface = nil;
return;
}
}
if (!packet && !wPacket) {
usleep(5000); // sleep for 5 milliseconds
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Wireless/Tapping/crc.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ uint32_t crc32(const char *buf, size_t len)
for ( ; len; --len, ++buf)
{
crc = UPDC32(*buf, crc);
printf("crc %x\n", crc);
}

return crc;
Expand Down

0 comments on commit 9780b1c

Please sign in to comment.