|
|
|
|
|
by maxlybbert
3451 days ago
|
|
I know three solutions for this: * (Classic): use goto so that instead of returning directly, all branches jump to a cleanup label. This is tricky to do well, but possible. * (Nonstandard): GCC offers a nonstandard function attribute to register a function as a destructor for this kind of thing. I'm sure they claim it was inspired by Scheme's dynamic-wind/dynamic-wind concept. * (Memory pooling): Apache APR relies heavily on memory pools. One feature of APR's memory pools is the ability to register functions to run (in, I believe, non-deterministic order) on data when the pool is eventually destroyed. |
|