Bug #44585 sp_cache behaves as memory leak
Submitted: 30 Apr 2009 20:27 Modified: 3 Feb 2012 14:27
Reporter: Andrii Nikitin Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S2 (Serious)
Version:5.0.72, 5.1.31 OS:Any
Assigned to: CPU Architecture:Any
Tags: Leak
Triage: Triaged: D2 (Serious) / R4 (High) / E4 (High)

[30 Apr 2009 20:27] Andrii Nikitin
Description:
sp_cache_insert is called for every stored procedure used and memory usage increased a little.

On huge number of of SP used memory will increase significantly (for 7000 SP used in connection memory usage increases on ~250Mb), which may lead to Out of Memory errors.

This is also security threat because once users can create SP on test database, they may increase server memory usage without any limit. 

How to repeat:
See source code in sql/sp.cc 
or 
call 7000 different stored procedures in single connection and monitor memory usage.

Suggested fix:
Not sure, probably limit sp_cache size or members count 
(like table_cache, we even may use the same variable).
[30 Apr 2009 20:54] Andrii Nikitin
I modified source code that sp_cache gets cleared at end of sp_show_create_procedure().
Memory usage become stable in testcase.
[18 May 2010 6:48] Shane Bester
well, no comments since bug was incorrectly marked as private.
[3 Feb 2012 14:27] Paul Dubois
Noted in 5.5.21, 5.6.5 changelogs.

The stored routine cache was subject to a small memory leak that over
time or with many routines being used could result in out-of-memory
errors.
[13 Apr 2012 7:01] Shane Bester
The variable to limit the cache size is: stored_program_cache