diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2017-10-05 16:02:57 +0200 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-10-09 10:27:41 -0700 |
commit | fca31be8332bd06f606cdc37a8da27be097e7c0c (patch) | |
tree | 01bac9803e9861c93cd894cd3fa3988ad31e73a0 /src/tls_wrap.cc | |
parent | 84579b1d7d92274b41a737e4d119d87807d486b1 (diff) | |
download | android-node-v8-fca31be8332bd06f606cdc37a8da27be097e7c0c.tar.gz android-node-v8-fca31be8332bd06f606cdc37a8da27be097e7c0c.tar.bz2 android-node-v8-fca31be8332bd06f606cdc37a8da27be097e7c0c.zip |
src: replace manual memory mgmt with std::string
PR-URL: https://github.com/nodejs/node/pull/15782
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/tls_wrap.cc')
-rw-r--r-- | src/tls_wrap.cc | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index dce05fabd6..093dc72af3 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -66,7 +66,6 @@ TLSWrap::TLSWrap(Environment* env, started_(false), established_(false), shutdown_(false), - error_(nullptr), cycle_depth_(0), eof_(false) { node::Wrap(object(), this); @@ -103,8 +102,6 @@ TLSWrap::~TLSWrap() { #ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB sni_context_.Reset(); #endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB - - ClearError(); } @@ -367,7 +364,7 @@ void TLSWrap::EncOutCb(WriteWrap* req_wrap, int status) { } -Local<Value> TLSWrap::GetSSLError(int status, int* err, const char** msg) { +Local<Value> TLSWrap::GetSSLError(int status, int* err, std::string* msg) { EscapableHandleScope scope(env()->isolate()); // ssl_ is already destroyed in reading EOF by close notify alert. @@ -398,13 +395,9 @@ Local<Value> TLSWrap::GetSSLError(int status, int* err, const char** msg) { OneByteString(env()->isolate(), mem->data, mem->length); Local<Value> exception = Exception::Error(message); - if (msg != nullptr) { - CHECK_EQ(*msg, nullptr); - char* const buf = new char[mem->length + 1]; - memcpy(buf, mem->data, mem->length); - buf[mem->length] = '\0'; - *msg = buf; - } + if (msg != nullptr) + msg->assign(mem->data, mem->data + mem->length); + BIO_free_all(bio); return scope.Escape(exception); @@ -516,12 +509,11 @@ bool TLSWrap::ClearIn() { // Error or partial write int err; - const char* error_str = nullptr; + std::string error_str; Local<Value> arg = GetSSLError(written, &err, &error_str); if (!arg.IsEmpty()) { MakePending(); - InvokeQueued(UV_EPROTO, error_str); - delete[] error_str; + InvokeQueued(UV_EPROTO, error_str.c_str()); clear_in_->Reset(); } @@ -570,13 +562,12 @@ int TLSWrap::ReadStop() { const char* TLSWrap::Error() const { - return error_; + return error_.empty() ? nullptr : error_.c_str(); } void TLSWrap::ClearError() { - delete[] error_; - error_ = nullptr; + error_.clear(); } @@ -624,11 +615,7 @@ int TLSWrap::DoWrite(WriteWrap* w, if (ssl_ == nullptr) { ClearError(); - - static char msg[] = "Write after DestroySSL"; - char* tmp = new char[sizeof(msg)]; - memcpy(tmp, msg, sizeof(msg)); - error_ = tmp; + error_ = "Write after DestroySSL"; return UV_EPROTO; } |