Initialize OpenSSL in DSA constructor

This fixes the double unlock errors that were popping up on circle
This commit is contained in:
Steven Fackler 2017-07-25 21:59:52 -07:00
parent a02f039c0c
commit 01927c19ac
2 changed files with 7 additions and 1 deletions

View File

@ -3,6 +3,7 @@ use std::sync::{Once, ONCE_INIT};
use std::mem; use std::mem;
use std::ptr; use std::ptr;
use std::process; use std::process;
use std::io::{self, Write};
use libc::{c_int, c_char, c_void, c_long, c_uchar, size_t, c_uint, c_ulong}; use libc::{c_int, c_char, c_void, c_long, c_uchar, size_t, c_uint, c_ulong};
#[cfg(not(ossl101))] #[cfg(not(ossl101))]
@ -748,7 +749,11 @@ unsafe extern "C" fn locking_function(mode: c_int, n: c_int, _file: *const c_cha
(*GUARDS)[n as usize] = Some(mutex.lock().unwrap()); (*GUARDS)[n as usize] = Some(mutex.lock().unwrap());
} else { } else {
if let None = (*GUARDS)[n as usize].take() { if let None = (*GUARDS)[n as usize].take() {
println!("lock {} already unlocked", n); let _ = writeln!(
io::stderr(),
"BUG: rust-openssl lock {} already unlocked, aborting",
n
);
process::abort(); process::abort();
} }
} }

View File

@ -79,6 +79,7 @@ impl DsaRef {
impl Dsa { impl Dsa {
/// Generate a DSA key pair. /// Generate a DSA key pair.
pub fn generate(bits: u32) -> Result<Dsa, ErrorStack> { pub fn generate(bits: u32) -> Result<Dsa, ErrorStack> {
ffi::init();
unsafe { unsafe {
let dsa = Dsa(try!(cvt_p(ffi::DSA_new()))); let dsa = Dsa(try!(cvt_p(ffi::DSA_new())));
try!(cvt(ffi::DSA_generate_parameters_ex( try!(cvt(ffi::DSA_generate_parameters_ex(