finish wait exit function without free memory