Fix possible memory leaks.