possible sql memory leak fixes