The branch main has been updated by emaste:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=4b60fac3a5c7a53f6d1a4480f37eb906bbacf21b

commit 4b60fac3a5c7a53f6d1a4480f37eb906bbacf21b
Author:     Ed Maste <ema...@freebsd.org>
AuthorDate: 2025-04-11 18:37:39 +0000
Commit:     Ed Maste <ema...@freebsd.org>
CommitDate: 2025-04-11 18:42:44 +0000

    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
---
 lib/libutil/kinfo_getfile.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/libutil/kinfo_getfile.c b/lib/libutil/kinfo_getfile.c
index f1441bdf771a..345da657df81 100644
--- a/lib/libutil/kinfo_getfile.c
+++ b/lib/libutil/kinfo_getfile.c
@@ -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)

Reply via email to