Added memory leak test and fixed memory leak with empy client