]> granicus.if.org Git - curl/commitdiff
openssl: fix per-thread memory leak usiong 1.0.1 or 1.0.2
authorDaniel Stenberg <daniel@haxx.se>
Mon, 29 Aug 2016 21:18:31 +0000 (23:18 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 14 Sep 2016 12:35:44 +0000 (14:35 +0200)
OpenSSL 1.0.1 and 1.0.2 build an error queue that is stored per-thread
so we need to clean it when easy handles are freed, in case the thread
will be killed in which the easy handle was used. All OpenSSL code in
libcurl should extract the error in association with the error already
so clearing this queue here should be harmless at worst.

Fixes #964

lib/vtls/openssl.c

index 0a46f9d43c81cf18834111cb9239c4e10e8af460..44a6bd82b3254b3d315f78381baa11279e5d90e9 100644 (file)
@@ -1056,6 +1056,14 @@ void Curl_ossl_close_all(struct Curl_easy *data)
 #else
   (void)data;
 #endif
+#if !defined(HAVE_ERR_REMOVE_THREAD_STATE_DEPRECATED) && \
+  defined(HAVE_ERR_REMOVE_THREAD_STATE)
+  /* OpenSSL 1.0.1 and 1.0.2 build an error queue that is stored per-thread
+     so we need to clean it here in case the thread will be killed. All OpenSSL
+     code should extract the error in association with the error so clearing
+     this queue here should be harmless at worst. */
+  ERR_remove_thread_state(NULL);
+#endif
 }
 
 /* ====================================================== */