How can I prevent the new indexing bug from creating useless pages on Google?

I have also a lot of page with 404 not found, should I redirect them or should I leave them as they are?
Thank you!