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

Memory leak from unfreed SSL_new #47

Closed
aaronovz1 opened this issue Oct 24, 2017 · 2 comments
Closed

Memory leak from unfreed SSL_new #47

aaronovz1 opened this issue Oct 24, 2017 · 2 comments

Comments

@aaronovz1
Copy link

aaronovz1 commented Oct 24, 2017

There is a case where SSL_free is not called on p_ssl_handle_. If the connection was never made then Disconnect() is never called (due to is_connected_ check) and p_ssl_handle_ is never freed. The fix that worked for me was to change destructor like so:

OpenSSLConnection::~OpenSSLConnection() {
            if (is_connected_) {
                Disconnect();
            }
            else {
                if (p_ssl_handle_) {
                    SSL_free(p_ssl_handle_);  // this is new
                }
            }
            SSL_CTX_free(p_ssl_context_);
#ifdef WIN32
            WSACleanup();
#endif
        }

There might also be another case if ConnectInternal() is called more then once before a Disconnect() is called. I can see this happening if there are reconnect attempts made externally. This can probably be fixed by just allocating p_ssl_handle_ once in ConnectInternal():

if (!p_ssl_handle_)
{
    p_ssl_handle_ = SSL_new(p_ssl_context_);
}
@vareddy-zz
Copy link
Contributor

Hi @aaronovz1 ,
Thanks for pointing this out. We will make a fix for this and will push it to master once we are done with our internal testing.
Thanks!
Varun

@sjmh3
Copy link

sjmh3 commented Oct 25, 2017

And, for the same reason, the TCP socket won't be closed either if, for example, it's connected but then the SSL handshake fails - is_connected_ won't be set true in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants