Make sure fd's are closed immediately, and cleanup properly