diff options
author | Cy Schubert <cy@FreeBSD.org> | 2024-05-10 15:15:56 +0000 |
---|---|---|
committer | Cy Schubert <cy@FreeBSD.org> | 2024-05-26 22:55:52 +0000 |
commit | 1f833b3fc9968c3dd7ed79ccf0525ebf16c891ad (patch) | |
tree | 85801af20e3b694584668aeb39ecec75ee71f72c /libntp/recvbuff.c | |
parent | ab1f1aa8333369a83ff284848fc3fc2e52d5f29f (diff) |
Diffstat (limited to 'libntp/recvbuff.c')
-rw-r--r-- | libntp/recvbuff.c | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/libntp/recvbuff.c b/libntp/recvbuff.c index d84a87d68501..6e7cda5d373d 100644 --- a/libntp/recvbuff.c +++ b/libntp/recvbuff.c @@ -93,41 +93,54 @@ initialise_buffer(recvbuf_t *buff) static void create_buffers( - size_t nbufs) + size_t nbufs +) { + static const u_int chunk = # ifndef DEBUG - static const u_int chunk = RECV_INC; + RECV_INC; # else /* Allocate each buffer individually so they can be free()d * during ntpd shutdown on DEBUG builds to keep them out of heap * leak reports. */ - static const u_int chunk = 1; + 1; # endif - - register recvbuf_t *bufp; - u_int i; - size_t abuf; + static int/*BOOL*/ doneonce; + recvbuf_t * bufp; + u_int i; + size_t abuf; /*[bug 3666]: followup -- reset shortfalls in all cases */ abuf = nbufs + buffer_shortfall; buffer_shortfall = 0; - if (limit_recvbufs <= total_recvbufs) + if (limit_recvbufs <= total_recvbufs) { + if (!doneonce) { + msyslog(LOG_CRIT, "Unable to allocate receive" + " buffer, %lu/%lu", + total_recvbufs, limit_recvbufs); + doneonce = TRUE; + } return; - - if (abuf < nbufs || abuf > RECV_BATCH) + } + + if (abuf < nbufs || abuf > RECV_BATCH) { abuf = RECV_BATCH; /* clamp on overflow */ - else + } else { abuf += (~abuf + 1) & (RECV_INC - 1); /* round up */ - - if (abuf > (limit_recvbufs - total_recvbufs)) + } + if (abuf > (limit_recvbufs - total_recvbufs)) { abuf = limit_recvbufs - total_recvbufs; + } abuf += (~abuf + 1) & (chunk - 1); /* round up */ while (abuf) { bufp = calloc(chunk, sizeof(*bufp)); if (!bufp) { + msyslog(LOG_CRIT, "Out of memory, allocating " + "%u recvbufs, %lu bytes", + chunk, (u_long)sizeof(*bufp) * chunk); limit_recvbufs = total_recvbufs; break; } |