kinfo_getfile: Add a comment explaining 4/3 ratio

We first get the expected size of the data from the kern.proc.filedesc
sysctl, allocate 4/3 of that size, and then fetch the data.  Add a
comment about the reason (the fd table may grow between the two calls).

Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Ed Maste 2025-04-11 14:37:39 -04:00
parent 7c72c0822b
commit 4b60fac3a5

View file

@ -27,6 +27,10 @@ kinfo_getfile(pid_t pid, int *cntp)
error = sysctl(mib, nitems(mib), NULL, &len, NULL, 0);
if (error)
return (NULL);
/*
* Add extra space as the table may grow between requesting the size
* and fetching the data.
*/
len = len * 4 / 3;
buf = malloc(len);
if (buf == NULL)