Some guarding against memory leaks