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

Decrease initial memory allocation for passwd and grp buffers #20

Closed
wants to merge 3 commits into from

Conversation

ericonr
Copy link
Contributor

@ericonr ericonr commented Jul 1, 2021

As explained in commit, we don't use the buffer lengths yet, because it will be part of the refactoring necessary to add caching.

Instead of querying sysconf once per loop for a value, we should just
store it during initialization, since it's environment information whose
value won't change during runtime.

Even so, since most of the time we are on musl, this function always
returns -1 and we end up using the BUF_LEN_DEFAULT buffer size.

For now, actually using these buffer lengths isn't implemented, because
the code that uses them is being refactored.
Move BUF_LEN_DEFAULT's value to the one used by glibc in their headers.
musl (as of version 1.2.2) defines NGROUPS_MAX to 32, but glibc and the
kernel define it to 65536. Since musl might change the definition at
some point, and the nss_initgroups interface allows the callee to
realloc the buffer, we don't have to allocate the maximum value upfront,
and can keep using 32 as a reasonable initial default.
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.

1 participant