Skip to content

Commit 2f1a498

Browse files
committed
Free returned dns-id
1 parent d67077f commit 2f1a498

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

crypto/x509/x509_compat_test.cc

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,23 +2344,26 @@ TEST(X509CompatTest, CommonNameToDNS) {
23442344
};
23452345

23462346
for (CommonNameToDNSTestParam &param : params) {
2347-
ASN1_STRING *ptr = NULL;
2347+
ASN1_STRING *asn1_str_ptr = NULL;
23482348
std::vector<uint8_t> cn(param.common_name.begin(), param.common_name.end());
2349-
ASSERT_GE(ASN1_mbstring_copy(&ptr, cn.data(), cn.size(), MBSTRING_UTF8,
2350-
V_ASN1_IA5STRING),
2349+
ASSERT_GE(ASN1_mbstring_copy(&asn1_str_ptr, cn.data(), cn.size(),
2350+
MBSTRING_UTF8, V_ASN1_IA5STRING),
23512351
0);
2352-
bssl::UniquePtr<ASN1_STRING> asn1_cn(ptr);
2352+
bssl::UniquePtr<ASN1_STRING> asn1_cn(asn1_str_ptr);
23532353
ASSERT_TRUE(asn1_cn);
2354-
unsigned char *dnsid = NULL;
2354+
unsigned char *dnsid_ptr = NULL;
23552355
size_t idlen = 0;
2356-
ASSERT_EQ(X509_V_OK, cn2dnsid(asn1_cn.get(), &dnsid, &idlen));
2356+
ASSERT_EQ(X509_V_OK, cn2dnsid(asn1_cn.get(), &dnsid_ptr, &idlen));
2357+
std::unique_ptr<unsigned char, void (*)(unsigned char *)> dnsid(
2358+
dnsid_ptr, [](unsigned char *ptr) { OPENSSL_free(ptr); });
23572359
if (param.expect_dns) {
2358-
ASSERT_TRUE(dnsid);
2359-
std::string dns_name(reinterpret_cast<char *>(dnsid), idlen);
2360+
ASSERT_TRUE(dnsid.get());
2361+
std::string dns_name(reinterpret_cast<char *>(dnsid.get()), idlen);
23602362
ASSERT_EQ(param.expected_dns_name, dns_name);
23612363
} else {
2362-
ASSERT_EQ(nullptr, dnsid);
2364+
ASSERT_FALSE(dnsid.get());
23632365
ASSERT_EQ((size_t)0, idlen);
23642366
}
23652367
}
23662368
}
2369+

0 commit comments

Comments
 (0)