Fix memory leak if mysql_server_prepare is enabled.

Fixes MySQL bug#41815, RT#76462.
Patch provided by KNI and Masahiro Chiba.