ssl: clear the OpenSSL locking function

We're freeing the memory which holds the locks so we must make sure that
the locking function doesn't try to use it.
Plug possible leak in the openssl locks
Merge pull request #2733 from akikoskinen/maint/v0.21

Backport two important changes to 0.21 branch