diff options
author | 2018-08-23 09:17:04 +0200 | |
---|---|---|
committer | 2018-08-23 09:17:04 +0200 | |
commit | 8c8030e5c737073cabb5907ff53d1277af081fed (patch) | |
tree | 15172ffe974bd37f3611ed73627377dc19b68744 | |
parent | Reworked main tableview switch layout & logic (diff) | |
download | wireguard-apple-8c8030e5c737073cabb5907ff53d1277af081fed.tar.xz wireguard-apple-8c8030e5c737073cabb5907ff53d1277af081fed.zip |
Add autorelease pool markers in Go callback functions.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r-- | WireGuardNetworkExtension/WireGuardGoWrapper.m | 100 |
1 files changed, 53 insertions, 47 deletions
diff --git a/WireGuardNetworkExtension/WireGuardGoWrapper.m b/WireGuardNetworkExtension/WireGuardGoWrapper.m index c4235b8..7631365 100644 --- a/WireGuardNetworkExtension/WireGuardGoWrapper.m +++ b/WireGuardNetworkExtension/WireGuardGoWrapper.m @@ -114,68 +114,74 @@ static void do_log(int level, const char *tag, const char *msg); static ssize_t do_read(const void *ctx, const unsigned char *buf, size_t len) { -// os_log_debug([WireGuardGoWrapper log], "do_read - start - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); - WireGuardGoWrapper *wrapper = (__bridge WireGuardGoWrapper *)ctx; - if (wrapper.isClosed) return -1; + @autoreleasepool { + os_log_debug([WireGuardGoWrapper log], "do_read - start - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); + WireGuardGoWrapper *wrapper = (__bridge WireGuardGoWrapper *)ctx; + if (wrapper.isClosed) return -1; - if (wrapper.handle < 0 || !wrapper.configured ) { -// os_log_debug([WireGuardGoWrapper log], "do_read - early - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); + if (wrapper.handle < 0 || !wrapper.configured ) { + os_log_debug([WireGuardGoWrapper log], "do_read - early - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); - return 0; - } + return 0; + } - NSData * __block packet = nil; -// NSNumber *protocol = nil; - dispatch_sync(wrapper.dispatchQueue, ^{ - [wrapper.condition lock]; - @synchronized(wrapper.packets) { - if (wrapper.packets.count == 0) { - os_log_debug([WireGuardGoWrapper log], "do_read - no packet - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); + NSData * __block packet = nil; +// NSNumber *protocol = nil; + dispatch_sync(wrapper.dispatchQueue, ^{ + [wrapper.condition lock]; + @synchronized(wrapper.packets) { + if (wrapper.packets.count == 0) { + os_log_debug([WireGuardGoWrapper log], "do_read - no packet - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); - return; - } + return; + } - packet = [wrapper.packets objectAtIndex:0]; - // protocol = [wrapper.protocols objectAtIndex:0]; - [wrapper.packets removeObjectAtIndex:0]; - [wrapper.protocols removeObjectAtIndex:0]; + packet = [wrapper.packets objectAtIndex:0]; + // protocol = [wrapper.protocols objectAtIndex:0]; + [wrapper.packets removeObjectAtIndex:0]; + [wrapper.protocols removeObjectAtIndex:0]; + } + }); + + if (packet == nil) { + os_log_debug([WireGuardGoWrapper log], "do_read - wait - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); + [wrapper.condition wait]; + [wrapper.condition unlock]; + return 0; + } else { + [wrapper.condition unlock]; } - }); - if (packet == nil) { - os_log_debug([WireGuardGoWrapper log], "do_read - wait - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); - [wrapper.condition wait]; - [wrapper.condition unlock]; - return 0; - } else { - [wrapper.condition unlock]; - } - - NSUInteger packetLength = [packet length]; - if (packetLength > len) { - // The packet will be dropped when we end up here. - os_log_debug([WireGuardGoWrapper log], "do_read - drop - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); - return 0; + NSUInteger packetLength = [packet length]; + if (packetLength > len) { + // The packet will be dropped when we end up here. + os_log_debug([WireGuardGoWrapper log], "do_read - drop - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); + return 0; + } + memcpy(buf, [packet bytes], packetLength); + os_log_debug([WireGuardGoWrapper log], "do_read - packet - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); + return packetLength; } - memcpy(buf, [packet bytes], packetLength); - os_log_debug([WireGuardGoWrapper log], "do_read - packet - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); - return packetLength; } static ssize_t do_write(const void *ctx, const unsigned char *buf, size_t len) { - os_log_debug([WireGuardGoWrapper log], "do_write - start"); - - WireGuardGoWrapper *wrapper = (__bridge WireGuardGoWrapper *)ctx; - //TODO: determine IPv4 or IPv6 status. - NSData *packet = [[NSData alloc] initWithBytes:buf length:len]; - [wrapper.packetFlow writePackets:@[packet] withProtocols:@[@AF_INET]]; - return len; + @autoreleasepool { + os_log_debug([WireGuardGoWrapper log], "do_write - start"); + + WireGuardGoWrapper *wrapper = (__bridge WireGuardGoWrapper *)ctx; + //TODO: determine IPv4 or IPv6 status. + NSData *packet = [[NSData alloc] initWithBytes:buf length:len]; + [wrapper.packetFlow writePackets:@[packet] withProtocols:@[@AF_INET]]; + return len; + } } static void do_log(int level, const char *tag, const char *msg) { - // TODO Get some details on the log level and distribute to matching log levels. - os_log([WireGuardGoWrapper log], "Log level %d for %{public}s: %{public}s", level, tag, msg); + @autoreleasepool { + // TODO Get some details on the log level and distribute to matching log levels. + os_log([WireGuardGoWrapper log], "Log level %d for %{public}s: %{public}s", level, tag, msg); + } } |