Don't call ERR_clear_system_error in so many places.

We've got it in entry points. That should be sufficient. (Do we even need it
there?)

Change-Id: I39b245a08fcde7b57e61b0bfc595c6ff4ce2a07a
Reviewed-on: https://boringssl-review.googlesource.com/8127
Reviewed-by: David Benjamin <davidben@google.com>
diff --git a/ssl/d1_clnt.c b/ssl/d1_clnt.c
index 19ad1f8..0b1701a 100644
--- a/ssl/d1_clnt.c
+++ b/ssl/d1_clnt.c
@@ -141,8 +141,6 @@
   assert(!ssl->server);
   assert(SSL_IS_DTLS(ssl));
 
-  ERR_clear_system_error();
-
   if (ssl->info_callback != NULL) {
     cb = ssl->info_callback;
   } else if (ssl->ctx->info_callback != NULL) {
diff --git a/ssl/d1_srvr.c b/ssl/d1_srvr.c
index 9913e73..5d17415 100644
--- a/ssl/d1_srvr.c
+++ b/ssl/d1_srvr.c
@@ -139,8 +139,6 @@
   assert(ssl->server);
   assert(SSL_IS_DTLS(ssl));
 
-  ERR_clear_system_error();
-
   if (ssl->info_callback != NULL) {
     cb = ssl->info_callback;
   } else if (ssl->ctx->info_callback != NULL) {
diff --git a/ssl/s3_clnt.c b/ssl/s3_clnt.c
index 2665f15..c341b2e 100644
--- a/ssl/s3_clnt.c
+++ b/ssl/s3_clnt.c
@@ -180,8 +180,6 @@
   assert(!ssl->server);
   assert(!SSL_IS_DTLS(ssl));
 
-  ERR_clear_system_error();
-
   if (ssl->info_callback != NULL) {
     cb = ssl->info_callback;
   } else if (ssl->ctx->info_callback != NULL) {
diff --git a/ssl/s3_srvr.c b/ssl/s3_srvr.c
index a28e6cd..0bac8ba 100644
--- a/ssl/s3_srvr.c
+++ b/ssl/s3_srvr.c
@@ -184,8 +184,6 @@
   assert(ssl->server);
   assert(!SSL_IS_DTLS(ssl));
 
-  ERR_clear_system_error();
-
   if (ssl->info_callback != NULL) {
     cb = ssl->info_callback;
   } else if (ssl->ctx->info_callback != NULL) {
diff --git a/ssl/ssl_buffer.c b/ssl/ssl_buffer.c
index 272b13b..efa2208 100644
--- a/ssl/ssl_buffer.c
+++ b/ssl/ssl_buffer.c
@@ -162,8 +162,6 @@
     return -1;
   }
 
-  ERR_clear_system_error();
-
   int ret;
   if (SSL_IS_DTLS(ssl)) {
     /* |len| is ignored for a datagram transport. */
@@ -301,7 +299,6 @@
     OPENSSL_PUT_ERROR(SSL, SSL_R_BIO_NOT_SET);
     return -1;
   }
-  ERR_clear_system_error();
 
   if (SSL_IS_DTLS(ssl)) {
     return dtls_write_buffer_flush(ssl);
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c
index 8e9b196..ec30dcf 100644
--- a/ssl/ssl_lib.c
+++ b/ssl/ssl_lib.c
@@ -559,6 +559,7 @@
   ssl->rwstate = SSL_NOTHING;
   /* Functions which use SSL_get_error must clear the error queue on entry. */
   ERR_clear_error();
+  ERR_clear_system_error();
 
   if (ssl->handshake_func == NULL) {
     OPENSSL_PUT_ERROR(SSL, SSL_R_CONNECTION_TYPE_NOT_SET);
@@ -665,6 +666,7 @@
   ssl->rwstate = SSL_NOTHING;
   /* Functions which use SSL_get_error must clear the error queue on entry. */
   ERR_clear_error();
+  ERR_clear_system_error();
 
   if (ssl->handshake_func == NULL) {
     OPENSSL_PUT_ERROR(SSL, SSL_R_UNINITIALIZED);