Do not try to close the same resource multiple times

@DeepDiver1975 @PVince81 @schiesbn