Adding a call to mysql_library_end(); to clean-up after closing the MySQL socket.  http://dev.mysql.com/doc/refman/5.5/en/mysql-library-end.html