Bug 1311319 - Part 3: Do not call PR_GetErrorText() when PR_GetErrorTextLength() is 0 in ssltunnel.cpp. r=jwalden, a=ritu
authorTooru Fujisawa <arai_a@mac.com>
Sun, 23 Oct 2016 01:46:34 +0900
changeset 358505 b82a286b69e040dc2e8f180e33cffd25f7a09ff4
parent 358504 1e0748e1dc350550d31ee9d254e6a726d92761de
child 358506 a6447a37d3e1c4a5327c236ff605ff2d46c33b38
push id1324
push usermtabara@mozilla.com
push dateMon, 16 Jan 2017 13:07:44 +0000
treeherdermozilla-release@a01c49833940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden, ritu
bugs1311319
milestone51.0a2
Bug 1311319 - Part 3: Do not call PR_GetErrorText() when PR_GetErrorTextLength() is 0 in ssltunnel.cpp. r=jwalden, a=ritu
testing/mochitest/ssltunnel/ssltunnel.cpp
--- a/testing/mochitest/ssltunnel/ssltunnel.cpp
+++ b/testing/mochitest/ssltunnel/ssltunnel.cpp
@@ -1552,20 +1552,23 @@ int main(int argc, char** argv)
     return 1;
   }
 
   PK11_SetPasswordFunc(password_func);
 
   // Initialize NSS
   if (NSS_Init(nssconfigdir.c_str()) != SECSuccess) {
     int32_t errorlen = PR_GetErrorTextLength();
-    char* err = new char[errorlen+1];
-    PR_GetErrorText(err);
-    LOG_ERROR(("Failed to init NSS: %s", err));
-    delete[] err;
+    if (errorlen) {
+      auto err = mozilla::MakeUnique<char[]>(errorlen + 1);
+      PR_GetErrorText(err.get());
+      LOG_ERROR(("Failed to init NSS: %s", err.get()));
+    } else {
+      LOG_ERROR(("Failed to init NSS: Cannot get error from NSPR."));
+    }
     PR_ShutdownThreadPool(threads);
     PR_DestroyCondVar(shutdown_condvar);
     PR_DestroyLock(shutdown_lock);
     return 1;
   }
 
   if (NSS_SetDomesticPolicy() != SECSuccess) {
     LOG_ERROR(("NSS_SetDomesticPolicy failed\n"));