Some fixes to the reference-counting in ENGINE code. First, there were a
few statements equivalent to "ENGINE_add(ENGINE_openssl())" etc. The inner call to ENGINE_openssl() (as with other functions like it) orphans a structural reference count. Second, the ENGINE_cleanup() function also needs to clean up the functional reference counts held internally as the list of "defaults" (ie. as used when RSA_new() requires an appropriate ENGINE reference). So ENGINE_clear_defaults() was created and is called from within ENGINE_cleanup(). Third, some of the existing code was logically broken in its treatment of reference counts and locking (my fault), so the necessary bits have been restructured and tidied up. To test this stuff, compiling with ENGINE_REF_COUNT_DEBUG will cause every reference count change (both structural and functional) to log a message to 'stderr'. Using with "openssl engine" for example shows this in action quite well as the 'engine' sub-command cleans up after itself properly. Also replaced some spaces with tabs.
This commit is contained in:
@@ -363,8 +363,12 @@ int ENGINE_cpy(ENGINE *dest, const ENGINE *src);
|
||||
int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
|
||||
CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
|
||||
int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg);
|
||||
/* Cleans the internal engine structure. This should only be used when the
|
||||
* application is about to exit. */
|
||||
/* Cleans the internal engine list. This should only be used when the
|
||||
* application is about to exit or restart operation (the next operation
|
||||
* requiring the ENGINE list will re-initialise it with defaults). NB: Dynamic
|
||||
* ENGINEs will only truly unload (including any allocated data or loaded
|
||||
* shared-libraries) if all remaining references are released too - so keys,
|
||||
* certificates, etc all need to be released for an in-use ENGINE to unload. */
|
||||
void ENGINE_cleanup(void);
|
||||
|
||||
/* These return values from within the ENGINE structure. These can be useful
|
||||
@@ -445,6 +449,12 @@ int ENGINE_set_default_BN_mod_exp_crt(ENGINE *e);
|
||||
* ENGINE_METHOD_*** defines above. */
|
||||
int ENGINE_set_default(ENGINE *e, unsigned int flags);
|
||||
|
||||
/* This function resets all the internal "default" ENGINEs (there's one for each
|
||||
* of the various algorithms) to NULL, releasing any references as appropriate.
|
||||
* This function is called as part of the ENGINE_cleanup() function, so there's
|
||||
* no need to call both (although no harm is done). */
|
||||
int ENGINE_clear_defaults(void);
|
||||
|
||||
/* Obligatory error function. */
|
||||
void ERR_load_ENGINE_strings(void);
|
||||
|
||||
|
Reference in New Issue
Block a user