fix memory leaks and rename dump files to use six digits in generation number