From 6e649333352ed71ff9e756c27cd7b0f18636a780 Mon Sep 17 00:00:00 2001 From: Francisco Date: Thu, 25 Feb 2021 12:16:41 +0000 Subject: [PATCH] handle the scenario when the network thread fails to allocate a byte buffer --- lib/src/common/network_utils.cc | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/src/common/network_utils.cc b/lib/src/common/network_utils.cc index 4234b6e84..e3f903de5 100644 --- a/lib/src/common/network_utils.cc +++ b/lib/src/common/network_utils.cc @@ -413,9 +413,13 @@ public: bool operator()(int fd) override { - srslte::unique_byte_buffer_t pdu(new byte_buffer_t()); - sockaddr_in from = {}; - socklen_t fromlen = sizeof(from); + srslte::unique_byte_buffer_t pdu = srslte::make_byte_buffer(); + if (pdu == nullptr) { + logger.error("Unable to allocate byte buffer"); + return true; + } + sockaddr_in from = {}; + socklen_t fromlen = sizeof(from); ssize_t n_recv = recvfrom(fd, pdu->msg, pdu->get_tailroom(), 0, (struct sockaddr*)&from, &fromlen); if (n_recv == -1 and errno != EAGAIN) { @@ -449,11 +453,15 @@ public: bool operator()(int fd) override { // inside rx_sockets thread. Read socket - srslte::unique_byte_buffer_t pdu = srslte::make_byte_buffer(); - sockaddr_in from = {}; - socklen_t fromlen = sizeof(from); - sctp_sndrcvinfo sri = {}; - int flags = 0; + srslte::unique_byte_buffer_t pdu = srslte::make_byte_buffer(); + if (pdu == nullptr) { + logger.error("Unable to allocate byte buffer"); + return true; + } + sockaddr_in from = {}; + socklen_t fromlen = sizeof(from); + sctp_sndrcvinfo sri = {}; + int flags = 0; ssize_t n_recv = sctp_recvmsg(fd, pdu->msg, pdu->get_tailroom(), (struct sockaddr*)&from, &fromlen, &sri, &flags); if (n_recv == -1 and errno != EAGAIN) { logger.error("Error reading from SCTP socket: %s", strerror(errno));