To be honest, could we replace above macros by inline functions or something else? define a CLEANUP() in each function seems very unreadable to me, sorry I'm not good at C programming.