Fix memory leak.

pull/36357/head
Matthew Stevenson 7 months ago
parent 66b31e55f6
commit a7239d7a83
  1. 2
      src/core/tsi/ssl_transport_security_utils.cc
  2. 3
      test/core/tsi/ssl_transport_security_utils_test.cc

@ -425,8 +425,8 @@ absl::StatusOr<EVP_PKEY*> ParsePemPrivateKey(
}
EVP_PKEY* pkey =
PEM_read_bio_PrivateKey(in, /*x=*/nullptr, /*cb=*/nullptr, /*u=*/nullptr);
BIO_free(in);
if (pkey == nullptr) {
BIO_free(in);
return absl::NotFoundError("No private key found.");
}
return pkey;

@ -820,18 +820,21 @@ TEST(ParsePemPrivateKeyTest, RsaSuccess1) {
absl::StatusOr<EVP_PKEY*> pkey = ParsePemPrivateKey(kPrivateKeyPem);
EXPECT_EQ(pkey.status(), absl::OkStatus());
EXPECT_NE(*pkey, nullptr);
EVP_PKEY_free(*pkey);
}
TEST(ParsePemPrivateKeyTest, RsaSuccess2) {
absl::StatusOr<EVP_PKEY*> pkey = ParsePemPrivateKey(kRsaPrivateKeyPem);
EXPECT_EQ(pkey.status(), absl::OkStatus());
EXPECT_NE(*pkey, nullptr);
EVP_PKEY_free(*pkey);
}
TEST(ParsePemPrivateKeyTest, EcSuccess) {
absl::StatusOr<EVP_PKEY*> pkey = ParsePemPrivateKey(kEcPrivateKeyPem);
EXPECT_EQ(pkey.status(), absl::OkStatus());
EXPECT_NE(*pkey, nullptr);
EVP_PKEY_free(*pkey);
}
} // namespace testing
} // namespace grpc_core

Loading…
Cancel
Save