fixed memory leaks

Fixed memory leaks