fixed memory leak with closing mysql resources