Database: fixed memory leak in query(sql)