Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7ca77dd

Browse filesBrowse files
tniessendanielleadams
authored andcommitted
src: avoid X509_free in loops in crypto_x509.cc
Use X509Pointer objects for automatic memory management instead. PR-URL: #44855 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent fd99b17 commit 7ca77dd
Copy full SHA for 7ca77dd

File tree

Expand file treeCollapse file tree

1 file changed

+7
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+7
-9
lines changed
Open diff view settings
Collapse file

‎src/crypto/crypto_context.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_context.cc
+7-9Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -699,15 +699,14 @@ void SecureContext::AddCACert(const FunctionCallbackInfo<Value>& args) {
699699
return;
700700

701701
X509_STORE* cert_store = SSL_CTX_get_cert_store(sc->ctx_.get());
702-
while (X509* x509 = PEM_read_bio_X509_AUX(
703-
bio.get(), nullptr, NoPasswordCallback, nullptr)) {
702+
while (X509Pointer x509 = X509Pointer(PEM_read_bio_X509_AUX(
703+
bio.get(), nullptr, NoPasswordCallback, nullptr))) {
704704
if (cert_store == root_cert_store) {
705705
cert_store = NewRootCertStore();
706706
SSL_CTX_set_cert_store(sc->ctx_.get(), cert_store);
707707
}
708-
X509_STORE_add_cert(cert_store, x509);
709-
SSL_CTX_add_client_CA(sc->ctx_.get(), x509);
710-
X509_free(x509);
708+
X509_STORE_add_cert(cert_store, x509.get());
709+
SSL_CTX_add_client_CA(sc->ctx_.get(), x509.get());
711710
}
712711
}
713712

@@ -1311,10 +1310,9 @@ unsigned long AddCertsFromFile( // NOLINT(runtime/int)
13111310
if (!bio)
13121311
return ERR_get_error();
13131312

1314-
while (X509* x509 =
1315-
PEM_read_bio_X509(bio.get(), nullptr, NoPasswordCallback, nullptr)) {
1316-
X509_STORE_add_cert(store, x509);
1317-
X509_free(x509);
1313+
while (X509Pointer x509 = X509Pointer(PEM_read_bio_X509(
1314+
bio.get(), nullptr, NoPasswordCallback, nullptr))) {
1315+
X509_STORE_add_cert(store, x509.get());
13181316
}
13191317

13201318
unsigned long err = ERR_peek_error(); // NOLINT(runtime/int)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.