Description:
MySQL causes the Service Control Manager (services.exe) to leak memory when MySQL is run as a Windows service and the service shuts itself down.
How to repeat:
Because the memory leak happens within an area that is allocated in advance of it's use, you'll have to exercise the memory leak multiple times before it will actually become visible. When the preallocated area is full, a new area will be allocated and you'll see the memory counters increase.
First, make sure that MySQL shuts itself down immediately by faking the base directory in my.ini. Just entering any non-existing directory should do.
Then type the following into a BAT file:
REM ==========================
:X
NET START MYSQL
GOTO X
REM ==========================
Start Task Manager and write down the value of the "VM Size" field for "services.exe".
Start an instance or two of the above BAT file and let it run for a couple of days.
Make sure that the machine is not doing anything else.
When you come back to the box after a day or two, the VM Size for services.exe should have increased.
On my box, it increases with an average rate of 4.75 bytes per second, in bundles of 24 kBytes, meaning that I see the first increase in VM size after ~90 minutes.
Suggested fix:
It would *probably* help to follow the Microsoft standard that defines how to communicate with the Service Control Manager.
Instead of terminating the MySQL server process with exit() when an error occurs, the MySQL main thread should notify MySQL's ServiceMain thread that it has terminated and whether an error has occurred.
The ServiceMain thread should then set the service status to STOPPED and if an error occurred, set the Win32ExitCode field to 1066 (service specific error) and the ServiceSpecificExitCode to something that the user can look up in the manual or with perror.
Then the ServiceMain thread should return, which in turn causes the service control command dispatcher thread (main application thread) to consider the service as being completely stopped, which will cause it to break out of StartServiceCtrlDispatcher, which in turn will cause the MySQL process to exit out of main() in a controlled fashion.