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

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ezurschmiede
Posts: 1
Joined: Wed 10 Apr 2019 14:44

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

Post by ezurschmiede » Wed 10 Apr 2019 15:09

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

ViktorV
Devart Team
Posts: 2656
Joined: Wed 30 Jul 2014 07:16

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

Post by ViktorV » Thu 11 Apr 2019 10:09

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.

Post Reply