Bug #88143 OpenRecordset leaking memory client side on Windows ODBC Client
Submitted: 18 Oct 2017 19:20 Modified: 4 Apr 2018 20:15
Reporter: Philip D'Ath Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / ODBC Severity:S1 (Critical)
Version:5.2.7, 5.3.7, 5.3.9 OS:Microsoft Windows (Server 2012)
Assigned to: Bogdan Degtyariov CPU Architecture:Any

[18 Oct 2017 19:20] Philip D'Ath
Description:
We use a 32 bit Microsoft Access 2013 front end that uses the 32 bit ODBC drivers to communicate with a MySQL server.

Originally we were using 5.2.7 of the ODBC drivers and MySQL 5.6.27.  At that time we were experiencing an issue where the application would slowly consume more and more memory on the client.
We then upgraded ODBC to 5.3.7 and the issue went away.

Next we upgraded MySQL from 5.6.27 to 5.7.16.  The memory consumption issued then started again (on the client side, not on the server).  This didn't seem to make any sense to us since there were no changes on the client side.

Next we upgraded the ODBC driver from 5.3.7 to 5.3.9.  The issue remained.

After enough queries have been executed Microsoft Access eventually crashes.  At this point we decided to look in greater detail what was causing the increasing memory consumption on the client side.

Note that it does not matter what type of query is being executed.

How to repeat:
Create a brand new Access database.  Create a brand new code module.  Copy and paste the code below.  Basically whenever OpenRecordSet is called 8KB to 12KB of memory seems to get leaked.  The below code deliberately puts this into an infinite loop to make the problem happen rapidly.  If you use Task Manager you'll rapidly see Microsoft Access consuming more and more memory, until eventually Microsoft Access crashes.

Option Compare Database
Option Explicit

Public Sub DemonstrateLeak()

Dim dbsMySQL As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String, strConnection As String

strConnection = "ODBC;DSN=etimber"

Set dbsMySQL = OpenDatabase("", False, False, strConnection)

strSQL = "SELECT Name FROM tblCustomer LIMIT 0,1"

Do

   Set rst = dbsMySQL.OpenRecordset(strSQL, dbOpenSnapshot, dbSQLPassThrough)
   rst.Close
   Set rst = Nothing

Loop

End Sub
[18 Oct 2017 21:45] Philip D'Ath
I forgot to mention, in the ODBC32 control panel only the following options are ticked:
* Enable dynamic cursors
* Return matches rows instead of affected rows
[25 Oct 2017 19:26] Philip D'Ath
Bump.  Any chance of confirming this bug?

The constant crashing through memory exhaustion on the client side is pretty painful.
[21 Nov 2017 12:18] Bogdan Degtyariov
Hi Philip,

Sorry for the late reply.
Thank you for your bug report.
The bug is verified. We are working on finding the solution.
[8 Dec 2017 4:34] Philip D'Ath
Bump.  How are you going with this one?
[13 Dec 2017 9:39] Bogdan Degtyariov
Posted by developer:
 
Memory leak happened because of a bug inside get_session_variable() function, which does not free result in case of error.
[13 Dec 2017 9:43] Bogdan Degtyariov
Posted by developer:
 
The fix is pushed into the source tree.
[13 Dec 2017 11:25] Philip D'Ath
I was going to try and pull the source code to compile it to test the fix.  But I can't see any changes.  Should it be here?

https://github.com/mysql/mysql-connector-odbc
[13 Dec 2017 20:24] Philip D'Ath
Alternatively, would it be possible to get the patched 32 bit ODBC driver so we can test the fix?
[21 Dec 2017 23:54] Philip Olson
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/ODBC 5.3.10 release and here's the changelog entry:

  Fixed an OpenRecordSet memory leak due to get_session_variable() not
  freeing a result for errors.

Thank you for the bug report.

Philip (nice name BTW, especially the part with just one 'l'), sorry but I am not sure when 
the release will happen but suspect the holidays will delay things a bit. The github repo
is only updated during the release. I'm afraid you'll have to wait a few more weeks or so.
[4 Apr 2018 5:04] andrew turnbull
Does this bug apply to ADODB recordsets also?
[4 Apr 2018 20:15] Philip D'Ath
I think it would also apply to ADODB.