uclcmd icon indicating copy to clipboard operation
uclcmd copied to clipboard

Automatically call cleanup() on exit

Open Savagedlight opened this issue 9 years ago • 1 comments

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.

Savagedlight avatar Jan 02 '16 06:01 Savagedlight

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, ...));

allanjude avatar Feb 02 '16 17:02 allanjude