From what I found out, there may be two causes for that:
  1. QSqlDatabase::addDatabase() and QSqlDatabase::removeDatabase() are not entirely thread-safe when using MySQL driver (maybe also when using other drivers, I didn't check them)
  2. MySQL driver doesn't clean up properly after itself when call to QSqlDatabase::open() fails.

See my response to your bug for more details.