@@ -66,7 +66,6 @@ TLSWrap::TLSWrap(Environment* env,
6666 started_(false ),
6767 established_(false ),
6868 shutdown_(false ),
69- error_(nullptr ),
7069 cycle_depth_(0 ),
7170 eof_(false ) {
7271 node::Wrap (object (), this );
@@ -103,8 +102,6 @@ TLSWrap::~TLSWrap() {
103102#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
104103 sni_context_.Reset ();
105104#endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
106-
107- ClearError ();
108105}
109106
110107
@@ -367,7 +364,7 @@ void TLSWrap::EncOutCb(WriteWrap* req_wrap, int status) {
367364}
368365
369366
370- Local<Value> TLSWrap::GetSSLError (int status, int * err, const char * * msg) {
367+ Local<Value> TLSWrap::GetSSLError (int status, int * err, std::string * msg) {
371368 EscapableHandleScope scope (env ()->isolate ());
372369
373370 // 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) {
398395 OneByteString (env ()->isolate (), mem->data , mem->length );
399396 Local<Value> exception = Exception::Error (message);
400397
401- if (msg != nullptr ) {
402- CHECK_EQ (*msg, nullptr );
403- char * const buf = new char [mem->length + 1 ];
404- memcpy (buf, mem->data , mem->length );
405- buf[mem->length ] = ' \0 ' ;
406- *msg = buf;
407- }
398+ if (msg != nullptr )
399+ msg->assign (mem->data , mem->data + mem->length );
400+
408401 BIO_free_all (bio);
409402
410403 return scope.Escape (exception);
@@ -516,12 +509,11 @@ bool TLSWrap::ClearIn() {
516509
517510 // Error or partial write
518511 int err;
519- const char * error_str = nullptr ;
512+ std::string error_str;
520513 Local<Value> arg = GetSSLError (written, &err, &error_str);
521514 if (!arg.IsEmpty ()) {
522515 MakePending ();
523- InvokeQueued (UV_EPROTO , error_str);
524- delete[] error_str;
516+ InvokeQueued (UV_EPROTO , error_str.c_str ());
525517 clear_in_->Reset ();
526518 }
527519
@@ -570,13 +562,12 @@ int TLSWrap::ReadStop() {
570562
571563
572564const char * TLSWrap::Error () const {
573- return error_;
565+ return error_. empty () ? nullptr : error_. c_str () ;
574566}
575567
576568
577569void TLSWrap::ClearError () {
578- delete[] error_;
579- error_ = nullptr ;
570+ error_.clear ();
580571}
581572
582573
@@ -624,11 +615,7 @@ int TLSWrap::DoWrite(WriteWrap* w,
624615
625616 if (ssl_ == nullptr ) {
626617 ClearError ();
627-
628- static char msg[] = " Write after DestroySSL" ;
629- char * tmp = new char [sizeof (msg)];
630- memcpy (tmp, msg, sizeof (msg));
631- error_ = tmp;
618+ error_ = " Write after DestroySSL" ;
632619 return UV_EPROTO ;
633620 }
634621
0 commit comments