I've seen this implementation of defer a few times now. I really dislike calling this defer (like the keyword in Go) as the given code won't be executed on return.
To my knowledge, you need a compiler extension to implement this in C (or use a C++ destructor).