Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think that dates back to assembly where you have to clear up a stack frame before returning.

Especially when the code to do that depends on the amount of locals, having only a single place where you assign space for locals and a single one where you revert that helps a lot.

It also can help in languages that don’t help you run cleanup code (closing files, freeing memory) at function exit. Change the code and forget to update one of your early exits, and you have a bug. If that exit is rare, that may ship and may become a vulnerability.



Additionally, something that is forgotten now that structured programming won so hard, and so little assembly is hand-written, is that it's possible to return to different places. As in, in case A return to address F, but in case B return to address G.


The Linux kernel still uses centralized exits in places, with goto to do cleanup.

https://github.com/torvalds/linux/blob/master/Documentation/...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: