Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No need to use OpenSSL malloc/free #10058

Merged
merged 1 commit into from Apr 3, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -117,26 +117,24 @@ std::atomic<bool> fReopenDebugLog(false);
CTranslationInterface translationInterface;

/** Init OpenSSL library multithreading support */
static CCriticalSection** ppmutexOpenSSL;
static std::unique_ptr<CCriticalSection[]> ppmutexOpenSSL;
void locking_callback(int mode, int i, const char* file, int line) NO_THREAD_SAFETY_ANALYSIS
{
if (mode & CRYPTO_LOCK) {
ENTER_CRITICAL_SECTION(*ppmutexOpenSSL[i]);
ENTER_CRITICAL_SECTION(ppmutexOpenSSL[i]);
} else {
LEAVE_CRITICAL_SECTION(*ppmutexOpenSSL[i]);
LEAVE_CRITICAL_SECTION(ppmutexOpenSSL[i]);
}
}

// Init
// Singleton for wrapping OpenSSL setup/teardown.
class CInit
{
public:
CInit()
{
// Init OpenSSL library multithreading support
ppmutexOpenSSL = (CCriticalSection**)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(CCriticalSection*));
for (int i = 0; i < CRYPTO_num_locks(); i++)
ppmutexOpenSSL[i] = new CCriticalSection();
ppmutexOpenSSL.reset(new CCriticalSection[CRYPTO_num_locks()]);
CRYPTO_set_locking_callback(locking_callback);

// OpenSSL can optionally load a config file which lists optional loadable modules and engines.
@@ -160,9 +158,8 @@ class CInit
RAND_cleanup();
// Shutdown OpenSSL library multithreading support
CRYPTO_set_locking_callback(NULL);
for (int i = 0; i < CRYPTO_num_locks(); i++)
delete ppmutexOpenSSL[i];
OPENSSL_free(ppmutexOpenSSL);

This comment has been minimized.

Copy link
@jonasschnelli

jonasschnelli Mar 23, 2017

Member

AFAIK it was slightly wrong to free the ppmutexOpenSSL via OPENSSL_free. IMO only objects alloced by OPENSSL_malloc() should use OPENSSL_free(). This change makes sense.
I was wrong: It is currently (master) alloced with OPENSSL_malloc.

This comment has been minimized.

Copy link
@laanwj

laanwj Mar 23, 2017

Member

It is allocated via OPENSSL_malloc

ppmutexOpenSSL = (CCriticalSection**)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(CCriticalSection*));

This comment has been minimized.

Copy link
@jonasschnelli

jonasschnelli Mar 23, 2017

Member

It is allocated via OPENSSL_malloc

Oh. Right.. it was. Nervermind then.

// Clear the set of locks now to maintain symmetry with the constructor.
ppmutexOpenSSL.reset();
}
}
instance_of_cinit;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.