I'm not sure how to approach it. The question was given after a lecture about Exceptions so I assume it has something to do with it.
Asked
Active
Viewed 296 times
1
-
Obvious possibilities would be things like losing power at the wrong time, or simply terminating the entire process (e.g., a `kill -9` under Linux or `TerminateProcess` under Windows). – Jerry Coffin Jun 04 '15 at 15:51
-
uhhh, something like exit(1)? – KitKat Jun 04 '15 at 15:56
-
calling `longjmp()` would prevent proper stack unwinding but would still move the stack pointer and program counter to some earlier location (which is why it's often considered a problematic call). – mah Jun 04 '15 at 15:57
-
I think if you throw an exception during the stack unwinding process it will just abort, idk if that counts as "preventing" though. – Borgleader Jun 04 '15 at 15:58
2 Answers
1
Default signal handlers, or calls to abort()
and exit()
could prevent stack unvinding.
And there's many more situations, like pointed out in mah's comment.
Especially any mechanism bypassing the c++ exception model will do so. Even threads have a model to do proper stack unwinding, with having them propagated to their parents (if they weren't detached).
-
thanks! So I get it as the stack unwinding process prevents memory leakage? – KitKat Jun 04 '15 at 16:02
-
-
-
One more special case: exception-during-unwinding causes abort() , which in tun stops unwinding (if I'm not mistaken) – No-Bugs Hare Jun 04 '15 at 16:14
-
@KitKat _"Does it do anything else?"_ It guarantees class destructors are called, whatever these will perform (closing files, detaching peripheral devices, closing network connections, etc.) – πάντα ῥεῖ Jun 04 '15 at 16:14
1
When a scope is exited, stack unwinding starts, which means the compiler inserts calls to destructors of automatic variables, as explained in this answer.
For this process to be prevented, you would need a sudden exiting of the process, which could be loss of power, force quitting the process through the command line, etc.

Community
- 1
- 1

Olivier Poulin
- 1,778
- 8
- 15