ssl_thread_init() uses wrong openssl threadid callback
The ssl_thread_init() sets thread and locking callbacks after checking whether
the application has already set its own thread callbacks.
Indeed it is correct to do the check and step back if the application has
installed callbacks already. The problem with the check is that it is
implemented incorrectly using the deprecated function CRYPTO_get_id_callback(),
which has been deprecated since version 1.0.0.
The consequence is that the check does not work when the application uses
the newer api (CRYPTO_THREADID_set_callback()). In my case both the
application and the connector set their own locking callbacks which
led to an application crash on application exit.
The attached patch fixes the check in a defensive way by checking for
both legacy callbacks and new style callbacks. It also fixes another location
where the deprecated api was used erroneously.