Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically call cleanup() on exit #5

Open
wants to merge 3 commits into
base: verbs
Choose a base branch
from

Conversation

Savagedlight
Copy link
Contributor

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.

Check if asprintf calls failed due to not enough memory, and if so,
print a message to stderr and abort()
@allanjude
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants