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

Side by Side Diff: runtime/bin/secure_socket_boringssl.cc

Issue 2741063003: [dart:io] Eagerly deallocate SSLFilter internals (Closed)
Patch Set: Created 3 years, 9 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 unified diff | Download patch
« no previous file with comments | « runtime/bin/secure_socket_boringssl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #if !defined(DART_IO_DISABLED) && !defined(DART_IO_SECURE_SOCKET_DISABLED) 5 #if !defined(DART_IO_DISABLED) && !defined(DART_IO_SECURE_SOCKET_DISABLED)
6 6
7 #include "platform/globals.h" 7 #include "platform/globals.h"
8 #if defined(TARGET_OS_ANDROID) || defined(TARGET_OS_LINUX) || \ 8 #if defined(TARGET_OS_ANDROID) || defined(TARGET_OS_LINUX) || \
9 defined(TARGET_OS_WINDOWS) || defined(TARGET_OS_FUCHSIA) 9 defined(TARGET_OS_WINDOWS) || defined(TARGET_OS_FUCHSIA)
10 10
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 ASSERT(!Dart_IsNull(protocols_handle)); 254 ASSERT(!Dart_IsNull(protocols_handle));
255 255
256 GetFilter(args)->Connect(host_name, context->context(), is_server, 256 GetFilter(args)->Connect(host_name, context->context(), is_server,
257 request_client_certificate, 257 request_client_certificate,
258 require_client_certificate, protocols_handle); 258 require_client_certificate, protocols_handle);
259 } 259 }
260 260
261 261
262 void FUNCTION_NAME(SecureSocket_Destroy)(Dart_NativeArguments args) { 262 void FUNCTION_NAME(SecureSocket_Destroy)(Dart_NativeArguments args) {
263 SSLFilter* filter = GetFilter(args); 263 SSLFilter* filter = GetFilter(args);
264 // The SSLFilter is deleted in the finalizer for the Dart object created by 264 // There are two paths that can clean up an SSLFilter object. First,
265 // SetFilter. There is no need to NULL-out the native field for the SSLFilter 265 // there is this explicit call to Destroy(), called from
266 // here because the SSLFilter won't be deleted until the finalizer for the 266 // _SecureFilter.destroy() in Dart code. After a call to destroy(), the Dart
267 // Dart object runs while the Dart object is being GCd. This approach avoids a 267 // code maintains the invariant that there will be no futher SSLFilter
268 // leak if Destroy isn't called, and avoids a NULL-dereference if Destroy is 268 // requests sent to the IO Service. Therefore, the internals of the SSLFilter
269 // called more than once. 269 // are safe to deallocate, but not the SSLFilter itself, which is already
270 // set up to be cleaned up by the finalizer.
271 //
272 // The second path is through the finalizer, which we have to do in case
273 // some mishap prevents a call to _SecureFilter.destroy().
270 filter->Destroy(); 274 filter->Destroy();
271 } 275 }
272 276
273 277
274 void FUNCTION_NAME(SecureSocket_Handshake)(Dart_NativeArguments args) { 278 void FUNCTION_NAME(SecureSocket_Handshake)(Dart_NativeArguments args) {
275 GetFilter(args)->Handshake(); 279 GetFilter(args)->Handshake();
276 } 280 }
277 281
278 282
279 void FUNCTION_NAME(SecureSocket_GetSelectedProtocol)( 283 void FUNCTION_NAME(SecureSocket_GetSelectedProtocol)(
(...skipping 1374 matching lines...) Expand 10 before | Expand all | Expand 10 after
1654 bool require_client_certificate) { 1658 bool require_client_certificate) {
1655 // The SSL_REQUIRE_CERTIFICATE option only takes effect if the 1659 // The SSL_REQUIRE_CERTIFICATE option only takes effect if the
1656 // SSL_REQUEST_CERTIFICATE option is also set, so set it. 1660 // SSL_REQUEST_CERTIFICATE option is also set, so set it.
1657 request_client_certificate = 1661 request_client_certificate =
1658 request_client_certificate || require_client_certificate; 1662 request_client_certificate || require_client_certificate;
1659 // TODO(24070, 24069): Implement setting the client certificate parameters, 1663 // TODO(24070, 24069): Implement setting the client certificate parameters,
1660 // and triggering rehandshake. 1664 // and triggering rehandshake.
1661 } 1665 }
1662 1666
1663 1667
1664 SSLFilter::~SSLFilter() { 1668 void SSLFilter::FreeResources() {
1665 if (ssl_ != NULL) { 1669 if (ssl_ != NULL) {
1666 SSL_free(ssl_); 1670 SSL_free(ssl_);
1667 ssl_ = NULL; 1671 ssl_ = NULL;
1668 } 1672 }
1669 if (socket_side_ != NULL) { 1673 if (socket_side_ != NULL) {
1670 BIO_free(socket_side_); 1674 BIO_free(socket_side_);
1671 socket_side_ = NULL; 1675 socket_side_ = NULL;
1672 } 1676 }
1673 if (hostname_ != NULL) { 1677 if (hostname_ != NULL) {
1674 free(hostname_); 1678 free(hostname_);
1675 hostname_ = NULL; 1679 hostname_ = NULL;
1676 } 1680 }
1677 for (int i = 0; i < kNumBuffers; ++i) { 1681 for (int i = 0; i < kNumBuffers; ++i) {
1678 if (buffers_[i] != NULL) { 1682 if (buffers_[i] != NULL) {
1679 delete[] buffers_[i]; 1683 delete[] buffers_[i];
1680 buffers_[i] = NULL; 1684 buffers_[i] = NULL;
1681 } 1685 }
1682 } 1686 }
1683 } 1687 }
1684 1688
1685 1689
1690 SSLFilter::~SSLFilter() {
1691 FreeResources();
1692 }
1693
1694
1686 void SSLFilter::Destroy() { 1695 void SSLFilter::Destroy() {
1687 for (int i = 0; i < kNumBuffers; ++i) { 1696 for (int i = 0; i < kNumBuffers; ++i) {
1688 if (dart_buffer_objects_[i] != NULL) { 1697 if (dart_buffer_objects_[i] != NULL) {
1689 Dart_DeletePersistentHandle(dart_buffer_objects_[i]); 1698 Dart_DeletePersistentHandle(dart_buffer_objects_[i]);
1690 dart_buffer_objects_[i] = NULL; 1699 dart_buffer_objects_[i] = NULL;
1691 } 1700 }
1692 } 1701 }
1693 if (string_start_ != NULL) { 1702 if (string_start_ != NULL) {
1694 Dart_DeletePersistentHandle(string_start_); 1703 Dart_DeletePersistentHandle(string_start_);
1695 string_start_ = NULL; 1704 string_start_ = NULL;
1696 } 1705 }
1697 if (string_length_ != NULL) { 1706 if (string_length_ != NULL) {
1698 Dart_DeletePersistentHandle(string_length_); 1707 Dart_DeletePersistentHandle(string_length_);
1699 string_length_ = NULL; 1708 string_length_ = NULL;
1700 } 1709 }
1701 if (handshake_complete_ != NULL) { 1710 if (handshake_complete_ != NULL) {
1702 Dart_DeletePersistentHandle(handshake_complete_); 1711 Dart_DeletePersistentHandle(handshake_complete_);
1703 handshake_complete_ = NULL; 1712 handshake_complete_ = NULL;
1704 } 1713 }
1705 if (bad_certificate_callback_ != NULL) { 1714 if (bad_certificate_callback_ != NULL) {
1706 Dart_DeletePersistentHandle(bad_certificate_callback_); 1715 Dart_DeletePersistentHandle(bad_certificate_callback_);
1707 bad_certificate_callback_ = NULL; 1716 bad_certificate_callback_ = NULL;
1708 } 1717 }
1718 FreeResources();
1709 } 1719 }
1710 1720
1711 1721
1712 /* Read decrypted data from the filter to the circular buffer */ 1722 /* Read decrypted data from the filter to the circular buffer */
1713 int SSLFilter::ProcessReadPlaintextBuffer(int start, int end) { 1723 int SSLFilter::ProcessReadPlaintextBuffer(int start, int end) {
1714 int length = end - start; 1724 int length = end - start;
1715 int bytes_processed = 0; 1725 int bytes_processed = 0;
1716 if (length > 0) { 1726 if (length > 0) {
1717 bytes_processed = SSL_read( 1727 bytes_processed = SSL_read(
1718 ssl_, reinterpret_cast<char*>((buffers_[kReadPlaintext] + start)), 1728 ssl_, reinterpret_cast<char*>((buffers_[kReadPlaintext] + start)),
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 return bytes_processed; 1796 return bytes_processed;
1787 } 1797 }
1788 1798
1789 } // namespace bin 1799 } // namespace bin
1790 } // namespace dart 1800 } // namespace dart
1791 1801
1792 #endif // defined(TARGET_OS_LINUX) 1802 #endif // defined(TARGET_OS_LINUX)
1793 1803
1794 #endif // !defined(DART_IO_DISABLED) && 1804 #endif // !defined(DART_IO_DISABLED) &&
1795 // !defined(DART_IO_SECURE_SOCKET_DISABLED) 1805 // !defined(DART_IO_SECURE_SOCKET_DISABLED)
OLDNEW
« no previous file with comments | « runtime/bin/secure_socket_boringssl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698