F/memory leak fixes