From: Dave Hart Date: Mon, 15 Apr 2024 22:28:07 +0000 (+0000) Subject: Log failures to allocate receive buffers. X-Git-Tag: NTP_4_2_8P18_RC1~9^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8d44cb30f8330a05b7c09c27cc6c7001430936a;p=thirdparty%2Fntp.git Log failures to allocate receive buffers. bk: 661da9f7Lqm5Yio4HJHgYeohvknUdw --- diff --git a/ChangeLog b/ChangeLog index 401140f76..cd6ec708d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -54,6 +54,7 @@ is disabled. * [Bug 3825] Don't touch HTML files unless building inside a BK repo. Fix the script checkHtmlFileDates. +* Log failures to allocate receive buffers. * Remove extraneous */ from libparse/ieee754io.c * Fix .datecheck target line in Makefile.am. * Update the copyright year. diff --git a/libntp/recvbuff.c b/libntp/recvbuff.c index d84a87d68..6e7cda5d3 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; }