with_resource(mutex file handle etc etc *o, func callback) is a safer pattern, for this reason. Thank you, Python
(with_resource is a generic example. Search for such capabilities in your library.)
Computers exist to automate. Let the computer remember to close resources upon scope end.
Go's defer is also helpful in this regard.