Import "Remove some code" from upstream OpenSSL

This imports upstream's
https://github.com/openssl/openssl/commit/6714cb1462c4980330e4cc4f65d7c10bc36b369d

Bug: 364634028
Change-Id: I270390f9a0ab8acb5ec508e2c992ccf6b1091a07
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/74768
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
diff --git a/crypto/pem/pem_lib.cc b/crypto/pem/pem_lib.cc
index 6683bee..69980fe 100644
--- a/crypto/pem/pem_lib.cc
+++ b/crypto/pem/pem_lib.cc
@@ -489,6 +489,7 @@
   unsigned char *buf = NULL;
   EVP_ENCODE_CTX ctx;
   int reason = ERR_R_BUF_LIB;
+  int retval = 0;
 
   EVP_EncodeInit(&ctx);
   nlen = strlen(name);
@@ -526,20 +527,19 @@
   if ((outl > 0) && (BIO_write(bp, (char *)buf, outl) != outl)) {
     goto err;
   }
-  OPENSSL_free(buf);
-  buf = NULL;
   if ((BIO_write(bp, "-----END ", 9) != 9) ||
       (BIO_write(bp, name, nlen) != nlen) ||
       (BIO_write(bp, "-----\n", 6) != 6)) {
     goto err;
   }
-  return i + outl;
+  retval = i + outl;
+
 err:
-  if (buf) {
-    OPENSSL_free(buf);
+  if (retval == 0) {
+    OPENSSL_PUT_ERROR(PEM, reason);
   }
-  OPENSSL_PUT_ERROR(PEM, reason);
-  return 0;
+  OPENSSL_free(buf);
+  return retval;
 }
 
 int PEM_read(FILE *fp, char **name, char **header, unsigned char **data,