]> granicus.if.org Git - python/commitdiff
bpo-37702: Fix SSL's certificate-store leak on Windows (GH-15632)
authorSteve Dower <steve.dower@python.org>
Mon, 9 Sep 2019 13:48:22 +0000 (06:48 -0700)
committerGitHub <noreply@github.com>
Mon, 9 Sep 2019 13:48:22 +0000 (06:48 -0700)
ssl_collect_certificates function in _ssl.c has a memory leak.
Calling CertOpenStore() and CertAddStoreToCollection(), a store's refcnt gets incremented by 2.
But CertCloseStore() is called only once and the refcnt leaves 1.

Misc/NEWS.d/next/Windows/2019-07-29-16-49-31.bpo-37702.Lj2f5e.rst [new file with mode: 0644]
Modules/_ssl.c

diff --git a/Misc/NEWS.d/next/Windows/2019-07-29-16-49-31.bpo-37702.Lj2f5e.rst b/Misc/NEWS.d/next/Windows/2019-07-29-16-49-31.bpo-37702.Lj2f5e.rst
new file mode 100644 (file)
index 0000000..67d53d4
--- /dev/null
@@ -0,0 +1,2 @@
+Fix memory leak on Windows in creating an SSLContext object or
+running urllib.request.urlopen('https://...').
\ No newline at end of file
index 089aa3b24a0261f9da8e072ff39694bd9cc62c5b..6f91b4882528516a058aa8494abfa33c33f03c02 100644 (file)
@@ -5581,6 +5581,7 @@ ssl_collect_certificates(const char *store_name)
             if (result) {
                 ++storesAdded;
             }
+            CertCloseStore(hSystemStore, 0);  /* flag must be 0 */
         }
     }
     if (storesAdded == 0) {