BUG: fix leak and possible null dereference