Correct the usage of realpath() in cleanup