fix possible memory leaks