Fix to #537, http://bugs.skysql.com/show_bug.cgi?id=537
mysql_thread_end was never called in this function