Comment Comment by stabbles You can have RAII with GCC extensions in C:char *buf __attribute__ ((__cleanup__(free_buf))) = malloc(1024);This calls free_buf(buf) when buf goes out of scope.I’ve actually seen projects use it in the wild to close files or free memory in branchy functions. [1][1] https://github.com/containers/bubblewrap/blob/c54bbc6d7b78e7... parent stabbles 3 years ago
char *buf __attribute__ ((__cleanup__(free_buf))) = malloc(1024);
This calls free_buf(buf) when buf goes out of scope.
I’ve actually seen projects use it in the wild to close files or free memory in branchy functions. [1]
[1] https://github.com/containers/bubblewrap/blob/c54bbc6d7b78e7...