fix memory leak of freeing DM