@@ -66,7 +66,6 @@ TLSWrap::TLSWrap(Environment* env,
66
66
started_(false ),
67
67
established_(false ),
68
68
shutdown_(false ),
69
- error_(nullptr ),
70
69
cycle_depth_(0 ),
71
70
eof_(false ) {
72
71
node::Wrap (object (), this );
@@ -103,8 +102,6 @@ TLSWrap::~TLSWrap() {
103
102
#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
104
103
sni_context_.Reset ();
105
104
#endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
106
-
107
- ClearError ();
108
105
}
109
106
110
107
@@ -367,7 +364,7 @@ void TLSWrap::EncOutCb(WriteWrap* req_wrap, int status) {
367
364
}
368
365
369
366
370
- Local<Value> TLSWrap::GetSSLError (int status, int * err, const char * * msg) {
367
+ Local<Value> TLSWrap::GetSSLError (int status, int * err, std::string * msg) {
371
368
EscapableHandleScope scope (env ()->isolate ());
372
369
373
370
// 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) {
398
395
OneByteString (env ()->isolate (), mem->data , mem->length );
399
396
Local<Value> exception = Exception::Error (message);
400
397
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
+
408
401
BIO_free_all (bio);
409
402
410
403
return scope.Escape (exception);
@@ -516,12 +509,11 @@ bool TLSWrap::ClearIn() {
516
509
517
510
// Error or partial write
518
511
int err;
519
- const char * error_str = nullptr ;
512
+ std::string error_str;
520
513
Local<Value> arg = GetSSLError (written, &err, &error_str);
521
514
if (!arg.IsEmpty ()) {
522
515
MakePending ();
523
- InvokeQueued (UV_EPROTO, error_str);
524
- delete[] error_str;
516
+ InvokeQueued (UV_EPROTO, error_str.c_str ());
525
517
clear_in_->Reset ();
526
518
}
527
519
@@ -570,13 +562,12 @@ int TLSWrap::ReadStop() {
570
562
571
563
572
564
const char * TLSWrap::Error () const {
573
- return error_;
565
+ return error_. empty () ? nullptr : error_. c_str () ;
574
566
}
575
567
576
568
577
569
void TLSWrap::ClearError () {
578
- delete[] error_;
579
- error_ = nullptr ;
570
+ error_.clear ();
580
571
}
581
572
582
573
@@ -624,11 +615,7 @@ int TLSWrap::DoWrite(WriteWrap* w,
624
615
625
616
if (ssl_ == nullptr ) {
626
617
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" ;
632
619
return UV_EPROTO;
633
620
}
634
621
0 commit comments