Automatically call cleanup() on exit
NOTE: This code is based on pull request 4 (asprintf ENOMEM checks). The diff will be significantly smaller once that PR is merged.
This removes all the manual calls to cleanup(), as they were always near the end of the code path, and uses atexit() (stdlib) to call cleanup() instead. It also improves the asprintf_check_enomem() function.
I would actually do this slightly differently
call the function: asprintf_checked() and make it take the arguments of asprintf, and call the asprintf for you (actually it would likely use vasprintf to just pass the var-args along)
so: int asprintf(&var, "fmt", var, ...);
would become: void asprintf_checked(&var, "fmt", var, ...);
instead of: asprintf_check_enomem(asprintf(&var, "fmt", var, ...));