Bug #33796 Memory leak for prepared statements in embedded server
Submitted: 10 Jan 2008 13:36 Modified: 2 Apr 2008 17:05
Reporter: Name Withheld Email Updates:
Status: Closed Impact on me:
Category:MySQL Server: Embedded Library ( libmysqld ) Severity:S1 (Critical)
Version:4.1.23 OS:Any
Assigned to: Alexey Botchkov CPU Architecture:Any
Triage: D2 (Serious) / R3 (Medium) / E3 (Medium)

[10 Jan 2008 13:36] Name Withheld
As of MySQL 4.1.21, the embedded server (libmysqld) has an important memory leak involving re-use of prepared statements.

In real usage scenarios, this bug can leak more than a megabyte per second.

The leak is still present in 4.1.23, on both Mac and Windows.  It's not present in 5.1.22.

This is probably related to bug #25492, which appeared in that same version (4.1.21).  Note that both these bugs may have been introduced by the fix for bug #16017.

How to repeat:
Run the attached test app, "test.cpp" (see build/use instructions at the head of that file).

The test app's memory usage will increase endlessly if you link against MySQL 4.1.23 and enable the app's reuse of prepared statements (using the switch described in the build/use instructions).

If you link against 4.1.20 or 5.1.22, or if you disable the app's reuse of prepared statements, its memory usage remains stable.
[10 Jan 2008 16:25] Hartmut Holzgraefe
self contained test project (including configure file)

Attachment: bug33796-0.1.tar.gz (application/x-gzip, text), 388.52 KiB.

[31 Jan 2008 17:04] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:


ChangeSet@1.2705, 2008-01-31 15:00:52+04:00, holyfoot@mysql.com +2 -0
  Bug #33796 Memory leak for prepared statements in embedded server.
  Field data for a query was stored to the stmt->alloc that is emptied
  with mysql_stmt_close statement only. That means a lot of memory can
  be occupied without a reason if used doesn't call mysql_stmt_close often.
[13 Mar 2008 19:27] Bugs System
Pushed into 6.0.5-alpha
[13 Mar 2008 19:34] Bugs System
Pushed into 5.1.24-rc
[13 Mar 2008 19:42] Bugs System
Pushed into 5.0.60
[13 Mar 2008 19:43] Bugs System
Pushed into 4.1.24
[2 Apr 2008 17:05] Jon Stephens
Documented bugfix in the 5.0.60, 5.1.23-ndb-6.3.11, 5.1.24, and 6.0.5 changelogs as follows:

        Reuse of prepared statements could cause a memory leak in the embedded