- ip = &ex_data[class_index];
- CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA);
- if (ip->meth == NULL) {
- ip->meth = sk_EX_CALLBACK_new_null();
- /* We push an initial value on the stack because the SSL
- * "app_data" routines use ex_data index zero. See RT 3710. */
- if (ip->meth == NULL
- || !sk_EX_CALLBACK_push(ip->meth, NULL)) {
- CRYPTOerr(CRYPTO_F_GET_AND_LOCK, ERR_R_MALLOC_FAILURE);
- CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA);
- return NULL;
- }
+ CRYPTO_THREAD_run_once(&ex_data_init, do_ex_data_init);
+
+ if (ex_data_lock == NULL) {
+ /*
+ * This can happen in normal operation when using CRYPTO_mem_leaks().
+ * The CRYPTO_mem_leaks() function calls OPENSSL_cleanup() which cleans
+ * up the locks. Subsequently the BIO that CRYPTO_mem_leaks() uses gets
+ * freed, which also attempts to free the ex_data. However
+ * CRYPTO_mem_leaks() ensures that the ex_data is freed early (i.e.
+ * before OPENSSL_cleanup() is called), so if we get here we can safely
+ * ignore this operation. We just treat it as an error.
+ */
+ return NULL;