Fix harmless read of uninitialized value; fix memory leaks in undo/redo