Merge pull request #408 from p12tic/fix-ssl-mem-leak

Fix memory leak during SSL socket shutdown
This commit is contained in:
Adrian Lucrèce Céleste 2019-08-22 12:54:27 -04:00 committed by GitHub
commit e31ebc1b22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 12 deletions

View File

@ -84,16 +84,8 @@ SecureSocket::~SecureSocket()
// could cause events to get called on a dead object. TCPSocket
// will do this, too, but the double-call is harmless
setJob(NULL);
if (m_ssl->m_ssl != NULL) {
SSL_shutdown(m_ssl->m_ssl);
freeSSLResources();
SSL_free(m_ssl->m_ssl);
m_ssl->m_ssl = NULL;
}
if (m_ssl->m_context != NULL) {
SSL_CTX_free(m_ssl->m_context);
m_ssl->m_context = NULL;
}
// removing sleep() because I have no idea why you would want to do it
// ... smells of trying to cover up a bug you don't understand
//ARCH->sleep(1);
@ -104,12 +96,24 @@ void
SecureSocket::close()
{
isFatal(true);
SSL_shutdown(m_ssl->m_ssl);
freeSSLResources();
TCPSocket::close();
}
void SecureSocket::freeSSLResources()
{
if (m_ssl->m_ssl != NULL) {
SSL_shutdown(m_ssl->m_ssl);
SSL_free(m_ssl->m_ssl);
m_ssl->m_ssl = NULL;
}
if (m_ssl->m_context != NULL) {
SSL_CTX_free(m_ssl->m_context);
m_ssl->m_context = NULL;
}
}
void
SecureSocket::connect(const NetworkAddress& addr)
{

View File

@ -88,6 +88,8 @@ private:
void handleTCPConnected(const Event& event, void*);
void freeSSLResources();
private:
Ssl* m_ssl;
bool m_secureReady;