From 1ff7977075f8d4d02f15ba3d9d3b78e91d7daaaf Mon Sep 17 00:00:00 2001 From: antoniocortes Date: Mon, 26 Nov 2018 20:47:05 -0800 Subject: [PATCH] IosSslSocket: add autoreleasepool to free temporary arrays in the SSL callbacks. Change on 2018/11/26 by antoniocortes ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=222932038 --- .../com/google/j2objc/net/ssl/IosSslSocket.m | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/jre_emul/Classes/com/google/j2objc/net/ssl/IosSslSocket.m b/jre_emul/Classes/com/google/j2objc/net/ssl/IosSslSocket.m index ae5ada966f..c634e2d0c4 100644 --- a/jre_emul/Classes/com/google/j2objc/net/ssl/IosSslSocket.m +++ b/jre_emul/Classes/com/google/j2objc/net/ssl/IosSslSocket.m @@ -336,42 +336,46 @@ - (jboolean)getEnableSessionCreation { @end static OSStatus SslReadCallback(SSLConnectionRef connection, void *data, size_t *dataLength) { - ComGoogleJ2objcNetSslIosSslSocket *socket = (ComGoogleJ2objcNetSslIosSslSocket *) connection; - IOSByteArray *array = [IOSByteArray arrayWithLength:*dataLength]; - jint processed; - @try { - processed = [[socket plainInputStream] readWithByteArray:array]; - } @catch (JavaIoIOException *e) { - JreStrongAssign(&socket->_sslException, e); - return errSSLInternal; - } + @autoreleasepool { + ComGoogleJ2objcNetSslIosSslSocket *socket = (ComGoogleJ2objcNetSslIosSslSocket *) connection; + IOSByteArray *array = [IOSByteArray arrayWithLength:*dataLength]; + jint processed; + @try { + processed = [[socket plainInputStream] readWithByteArray:array]; + } @catch (JavaIoIOException *e) { + JreStrongAssign(&socket->_sslException, e); + return errSSLInternal; + } - if (processed < 0) { - *dataLength = 0; - return errSSLClosedGraceful; - } + if (processed < 0) { + *dataLength = 0; + return errSSLClosedGraceful; + } - OSStatus status = processed < *dataLength ? errSSLWouldBlock : errSecSuccess; - if (processed > 0) { - [array getBytes:(jbyte *)data length:processed]; + OSStatus status = processed < *dataLength ? errSSLWouldBlock : errSecSuccess; + if (processed > 0) { + [array getBytes:(jbyte *)data length:processed]; + } + *dataLength = processed; + return status; } - *dataLength = processed; - return status; } static OSStatus SslWriteCallback(SSLConnectionRef connection, const void *data, size_t *dataLength) { - ComGoogleJ2objcNetSslIosSslSocket *socket = (ComGoogleJ2objcNetSslIosSslSocket *) connection; - IOSByteArray *array = [IOSByteArray arrayWithBytes:(const jbyte *)data count:*dataLength]; - @try { - [[socket plainOutputStream] writeWithByteArray:array]; - [[socket plainOutputStream] flush]; - } @catch (JavaIoIOException *e) { - JreStrongAssign(&socket->_sslException, e); - return errSSLInternal; + @autoreleasepool { + ComGoogleJ2objcNetSslIosSslSocket *socket = (ComGoogleJ2objcNetSslIosSslSocket *) connection; + IOSByteArray *array = [IOSByteArray arrayWithBytes:(const jbyte *)data count:*dataLength]; + @try { + [[socket plainOutputStream] writeWithByteArray:array]; + [[socket plainOutputStream] flush]; + } @catch (JavaIoIOException *e) { + JreStrongAssign(&socket->_sslException, e); + return errSSLInternal; + } + return errSecSuccess; } - return errSecSuccess; } static void checkStatus(OSStatus status) {