Fix #66952: refactor openssl_open() a little bit to avoid memory leak in all cases