Problem: fd leak in tweetnacl with one ctx per thread

Solution: add a crypto [de-]initialiser, refcounted and serialised
through critical sections.
This is necessary as utility APIs such as zmq_curve_keypair also
call into the sodium/tweetnacl libraries and need the initialisation
outside of the zmq context.
Also the libsodium documentation explicitly says that sodium_init
must not be called concurrently from multiple threads, which could
have happened until now. Also the randombytes_close function does
not appear to be thread safe either.
This change guarantees that the library is initialised only once at
any given time across the whole program.
Fixes #2632
This commit is contained in:
Luca Boccassi
2017-07-27 14:43:14 +01:00
parent a7bf010ee2
commit e015a0f8b9
7 changed files with 113 additions and 37 deletions

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
Copyright (c) 2007-2017 Contributors as noted in the AUTHORS file
This file is part of libzmq, the ZeroMQ core engine in C++.
@@ -233,8 +233,6 @@ namespace zmq
int vmci_family;
mutex_t vmci_sync;
#endif
mutex_t crypto_sync;
};
}