+ ad->ctx = NULL;
+}
+
+/*
+ * Allocate a given CRYPTO_EX_DATA item using the class specific allocation
+ * function
+ */
+int CRYPTO_alloc_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad,
+ int idx)
+{
+ EX_CALLBACK *f;
+ EX_CALLBACKS *ip;
+ void *curval;
+ OSSL_EX_DATA_GLOBAL *global = openssl_ctx_get_ex_data_global(ad->ctx);
+
+ if (global == NULL)
+ return 0;
+
+ curval = CRYPTO_get_ex_data(ad, idx);
+
+ /* Already there, no need to allocate */
+ if (curval != NULL)
+ return 1;
+
+ ip = get_and_lock(ad->ctx, class_index);
+ if (ip == NULL)
+ return 0;
+ f = sk_EX_CALLBACK_value(ip->meth, idx);
+ CRYPTO_THREAD_unlock(global->ex_data_lock);
+
+ /*
+ * This should end up calling CRYPTO_set_ex_data(), which allocates
+ * everything necessary to support placing the new data in the right spot.
+ */
+ if (f->new_func == NULL)
+ return 0;
+
+ f->new_func(obj, NULL, ad, idx, f->argl, f->argp);
+
+ return 1;