Chromium Code Reviews| Index: runtime/bin/secure_socket.cc |
| diff --git a/runtime/bin/secure_socket.cc b/runtime/bin/secure_socket.cc |
| index c32301d6b7adc557c25469a3efac0d7b6a810d7b..067068319bcecb796bce944533e3995823577518 100644 |
| --- a/runtime/bin/secure_socket.cc |
| +++ b/runtime/bin/secure_socket.cc |
| @@ -100,14 +100,28 @@ static SSL_CTX* GetSecurityContext(Dart_NativeArguments args) { |
| } |
| +static void FreeSecurityContext( |
| + void* isolate_data, |
| + Dart_WeakPersistentHandle handle, |
| + void* context_pointer) { |
| + SSL_CTX* context = static_cast<SSL_CTX*>(context_pointer); |
| + SSL_CTX_free(context); |
| +} |
| + |
| + |
| static void SetSecurityContext(Dart_NativeArguments args, |
| SSL_CTX* context) { |
| + const int approximate_size_of_context = 1500; |
| Dart_Handle dart_this = ThrowIfError(Dart_GetNativeArgument(args, 0)); |
| ASSERT(Dart_IsInstance(dart_this)); |
| ThrowIfError(Dart_SetNativeInstanceField( |
| dart_this, |
| kSecurityContextNativeFieldIndex, |
| reinterpret_cast<intptr_t>(context))); |
| + Dart_NewWeakPersistentHandle(dart_this, |
| + context, |
| + approximate_size_of_context, |
| + FreeSecurityContext); |
| } |
| @@ -313,9 +327,6 @@ void FUNCTION_NAME(SecurityContext_Allocate)(Dart_NativeArguments args) { |
| SSL_CTX_set_cipher_list(context, "HIGH:MEDIUM"); |
| SSL_CTX_set_cipher_list_tls11(context, "HIGH:MEDIUM"); |
| SetSecurityContext(args, context); |
| - // TODO(whesse): Use WeakPersistentHandle to free the SSL_CTX |
| - // when the object is GC'd. Also free the alpn_select_cb data pointer, |
|
Søren Gjesse
2015/09/02 16:24:31
How about the alpn_select_cb data pointer mentione
Bill Hesse
2015/09/03 08:47:00
The TODO is moved below. The issue is harder to r
|
| - // if non-null (allocated in SetAlpnProtocolList). |
| } |
| @@ -825,7 +836,9 @@ static void SetAlpnProtocolList(Dart_Handle protocols_handle, |
| // TODO(whesse): If this function is called again, free the previous |
| // protocol_string_copy. It may be better to keep this as a native |
| // field on the Dart object, since fetching it from the structure is |
| - // not in the public api. Also free this when the context is destroyed. |
| + // not in the public api. |
| + // Also free protocol_string_copy when the context is destroyed, |
| + // in FreeSecurityContext() |
| } else { |
| // The function makes a local copy of protocol_string, which it owns. |
| if (ssl != NULL) { |
| @@ -1022,6 +1035,10 @@ void SSLFilter::Destroy() { |
| SSL_free(ssl_); |
| ssl_ = NULL; |
| } |
| + if (socket_side_ != NULL) { |
| + BIO_free(socket_side_); |
| + socket_side_ = NULL; |
| + } |
| for (int i = 0; i < kNumBuffers; ++i) { |
| Dart_DeletePersistentHandle(dart_buffer_objects_[i]); |
| delete[] buffers_[i]; |