Page 1 of 1

OpenSSL Memory-Leak in CRVioTcpSSL.pas (MySQL/MariaDB with OpenSSL)

Posted: Wed 10 Apr 2019 15:09
by ezurschmiede
Hi

I just found a little but bad memory leak troubled some of my installations as the customer changed his MariaDB-Connection to use SSL. The service got out of memory regularely after a few days.

Please include this fix in the next release.

The leak is in CRVioTcpSSL.pas where some calls to SSL_free and SSL_CTX_free are missing.

This is my fix (introduced a destructor to free the SSL stuff allocated earlier):

Code: Select all

...
var
  SSL_CTX_free: procedure(_para1: IntPtr); cdecl; // EZ - added for memleak fix
...
AssignProc(hssleay, @SSL_CTX_free, 'SSL_CTX_free'); // EZ - added for memleak fix
...
destructor TCRVioTcpSSL.Destroy;
begin
  // EZ - fix memleak start
  if Fnewcon.ssl_context_ <> nil then
  begin
    SSL_CTX_free(Fnewcon.ssl_context_);
    Fnewcon.ssl_context_ := nil;
  end;

  if Fssl_arg <> nil then
  begin
    SSL_free(Fssl_arg);
    Fssl_arg := nil;
  end;
  // EZ - fix memleak end

  inherited;
end;
best regards
Elias Zurschmiede

Re: OpenSSL Memory-Leak in CRVioTcpSSL.pas (MySQL/MariaDB with OpenSSL)

Posted: Thu 11 Apr 2019 10:09
by ViktorV
Thank you for the information.
You found a right solution to the issue.
We have already fixed this issue. This fix will be included in the next UniDAC build.