Skip to content

Commit 40abc65

Browse files
miss-islingtonjelle-openaiJelleZijlstra
authored
[3.15] gh-159739: Release SSL resources on error paths (GH-159745) (#159761)
gh-159739: Release SSL resources on error paths (GH-159745) 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. (cherry picked from commit b2b0a33) Co-authored-by: Jelle Zijlstra <jelle@openai.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent 02f9a2e commit 40abc65

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
@@ -1576,6 +1576,7 @@ _get_peer_alt_names (_sslmodulestate *state, X509 *certificate) {
15761576

15771577

15781578
fail:
1579+
sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free);
15791580
if (biobuf != NULL)
15801581
BIO_free(biobuf);
15811582

‎Modules/_ssl/debughelpers.c‎

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

230230
self->keylog_bio = BIO_new_fp(fp, BIO_CLOSE | BIO_FP_TEXT);
231231
if (self->keylog_bio == NULL) {
232+
fclose(fp);
232233
PyErr_SetString(get_state_ctx(self)->PySSLErrorObject,
233234
"Can't malloc memory for keylog file");
234235
return -1;

0 commit comments

Comments
 (0)