Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(643)

Unified Diff: runtime/bin/secure_socket.cc

Issue 1308953007: Fix two memory leaks in SecureSocket. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove change to comment. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
- // 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];
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698