Skip to content

Commit 96aeed5

Browse files
committed
gh-159739: Release SSL resources on error paths
Free decoded subject alternative names when certificate conversion fails, and close the key log file if the BIO allocation fails. Backport to 3.15 and 3.14.
1 parent a071788 commit 96aeed5

3 files changed

Lines changed: 4 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix resource leaks in :mod:`ssl` when certificate conversion or key log setup
2+
fails.

‎Modules/_ssl.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,7 @@ _get_peer_alt_names (_sslmodulestate *state, X509 *certificate) {
15491549

15501550

15511551
fail:
1552+
sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free);
15521553
if (biobuf != NULL)
15531554
BIO_free(biobuf);
15541555

‎Modules/_ssl/debughelpers.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ _PySSLContext_set_keylog_filename(PyObject *op, PyObject *arg,
232232

233233
self->keylog_bio = BIO_new_fp(fp, BIO_CLOSE | BIO_FP_TEXT);
234234
if (self->keylog_bio == NULL) {
235+
fclose(fp);
235236
PyErr_SetString(get_state_ctx(self)->PySSLErrorObject,
236237
"Can't malloc memory for keylog file");
237238
return -1;

0 commit comments

Comments
 (0)