Fix possible memory leaks