Skip to content

Commit

Permalink
IosSslSocket: add autoreleasepool to free temporary arrays in the SSL…
Browse files Browse the repository at this point in the history
… callbacks.

	Change on 2018/11/26 by antoniocortes <[email protected]>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=222932038
  • Loading branch information
antonio-cortes-perez committed Nov 27, 2018
1 parent 33d327e commit 1ff7977
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions jre_emul/Classes/com/google/j2objc/net/ssl/IosSslSocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 1ff7977

Please sign in to comment.