- {
- int i;
-
- if(e == NULL)
- {
- ENGINEerr(ENGINE_F_ENGINE_FREE,
- ERR_R_PASSED_NULL_PARAMETER);
- return 0;
- }
- if(locked)
- i = CRYPTO_add(&e->struct_ref,-1,CRYPTO_LOCK_ENGINE);
- else
- i = --e->struct_ref;
- engine_ref_debug(e, 0, -1)
- if (i > 0) return 1;
-#ifdef REF_CHECK
- if (i < 0)
- {
- fprintf(stderr,"ENGINE_free, bad structural reference count\n");
- abort();
- }
-#endif
- /* Give the ENGINE a chance to do any structural cleanup corresponding
- * to allocation it did in its constructor (eg. unload error strings) */
- if(e->destroy)
- e->destroy(e);
- CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ENGINE, e, &e->ex_data);
- OPENSSL_free(e);
- return 1;
- }
+{
+ int i;
+
+ if (e == NULL)
+ return 1;
+ if (locked)
+ i = CRYPTO_add(&e->struct_ref, -1, CRYPTO_LOCK_ENGINE);
+ else
+ i = --e->struct_ref;
+ engine_ref_debug(e, 0, -1)
+ if (i > 0)
+ return 1;
+ REF_ASSERT_ISNT(i < 0);
+ /* Free up any dynamically allocated public key methods */
+ engine_pkey_meths_free(e);
+ engine_pkey_asn1_meths_free(e);
+ /*
+ * Give the ENGINE a chance to do any structural cleanup corresponding to
+ * allocation it did in its constructor (eg. unload error strings)
+ */
+ if (e->destroy)
+ e->destroy(e);
+ CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ENGINE, e, &e->ex_data);
+ OPENSSL_free(e);
+ return 1;
+}