RAII in C
RAII in C
Posted Apr 9, 2014 13:02 UTC (Wed) by psevon (guest, #96490)In reply to: RAII in C by bronson
Parent article: A longstanding GnuTLS certificate validation botch
The problem with cleanup is that it doesn't allow for passing the allocated object to an outer scope and stil be subject to automatic cleanup, which is one of the main strengths of smartpointers in C++. It also doesn't work nicely together with setjmp/longjmp based exception mechanisms, since the intermediate scope (i.e., functions between the function doing setjmp and function doing longjmp in the call stack) cleanups will never be triggered. See my project https://github.com/psevon/exceptions-and-raii-in-c for an implementation of smartpointers and exceptions in C that avoids the above mentioned problems.
