Yes, I (and a lot of others) think this is the most powerful feature of C++, destructors.
I've seen constructions in C also. The source code of Systemd uses this, you use a
GCC specific attribute, to register a function that gets called when the block exists.
This is used to free stuff like your example. I think in the systemd case, they should
have used C++ instead, because you should use a language in a way the designers
intended. I would *love* adding some C++ features like functions on objects or
interfaces, and destructors, but not in the C++ way. That would be C2++ and is
currently planned for 2034