fix error found by coverity: check if ctx is != NULL before calling BN_CTX_end()