getpwent_r(3) needs gr->gr_mem to be freed, but that's not documented
Collin Funk
collin.funk1@gmail.com
Sun Sep 28 22:43:54 GMT 2025
Alejandro Colomar <alx@kernel.org> writes:
> Hmmm, that's good. Thanks! At least, the user doesn't need to free(3)
> anything weird.
>
> So, a good estimate of the size to be allocated prior to the
> sgetgrent_r() call should be:
>
> size = strlen(s) + 1 + strchrcnt(s, ',') + 2;
>
> That would be wasting a little bit if there are any commas outside of
> the fourth ':'-delimited field, but it should work.
You can guess a value and then grow the buffer as long as errno == ERANGE.
> BTW, where's this exactly in the glibc source code? It's a bit hard to
> follow.
In nss you can find <FUNCTION-NAME>.c and then follow the includes and
macros. I agree it is a bit hard to follow. :)
Collin
More information about the Libc-alpha
mailing list