client: fix possible memory leaks