From 390a463d9f1fb2ed7f8d0fbe62ff0f74d3c94498 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 6 Mar 2018 12:41:44 +0100 Subject: [PATCH] Check for PDU allocation and add warnings --- lib/src/upper/pdcp.cc | 12 ++++++++++-- lib/src/upper/rlc.cc | 37 +++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/lib/src/upper/pdcp.cc b/lib/src/upper/pdcp.cc index 188c56c97..cb3ec7d84 100644 --- a/lib/src/upper/pdcp.cc +++ b/lib/src/upper/pdcp.cc @@ -92,8 +92,12 @@ bool pdcp::is_drb_enabled(uint32_t lcid) void pdcp::write_sdu(uint32_t lcid, byte_buffer_t *sdu) { - if(valid_lcid(lcid)) + if(valid_lcid(lcid)) { pdcp_array[lcid].write_sdu(sdu); + } else { + pdcp_log->warning("Writing sdu: lcid=%d. Deallocating sdu\n", lcid); + byte_buffer_pool::get_instance()->deallocate(sdu); + } } void pdcp::add_bearer(uint32_t lcid, srslte_pdcp_config_t cfg) @@ -149,8 +153,12 @@ void pdcp::enable_encryption(uint32_t lcid) *******************************************************************************/ void pdcp::write_pdu(uint32_t lcid, byte_buffer_t *pdu) { - if(valid_lcid(lcid)) + if(valid_lcid(lcid)) { pdcp_array[lcid].write_pdu(pdu); + } else { + pdcp_log->warning("Writing pdu: lcid=%d. Deallocating pdu\n", lcid); + byte_buffer_pool::get_instance()->deallocate(pdu); + } } void pdcp::write_pdu_bcch_bch(byte_buffer_t *sdu) diff --git a/lib/src/upper/rlc.cc b/lib/src/upper/rlc.cc index a626f3002..e771c34a2 100644 --- a/lib/src/upper/rlc.cc +++ b/lib/src/upper/rlc.cc @@ -187,10 +187,14 @@ void rlc::write_pdu_bcch_bch(uint8_t *payload, uint32_t nof_bytes) rlc_log->info_hex(payload, nof_bytes, "BCCH BCH message received."); dl_tput_bytes[0] += nof_bytes; byte_buffer_t *buf = pool_allocate; - memcpy(buf->msg, payload, nof_bytes); - buf->N_bytes = nof_bytes; - buf->set_timestamp(); - pdcp->write_pdu_bcch_bch(buf); + if (buf) { + memcpy(buf->msg, payload, nof_bytes); + buf->N_bytes = nof_bytes; + buf->set_timestamp(); + pdcp->write_pdu_bcch_bch(buf); + } else { + rlc_log->error("Fatal error: Out of buffers from the pool in write_pdu_bcch_bch()\n"); + } } void rlc::write_pdu_bcch_dlsch(uint8_t *payload, uint32_t nof_bytes) @@ -198,10 +202,14 @@ void rlc::write_pdu_bcch_dlsch(uint8_t *payload, uint32_t nof_bytes) rlc_log->info_hex(payload, nof_bytes, "BCCH TXSCH message received."); dl_tput_bytes[0] += nof_bytes; byte_buffer_t *buf = pool_allocate; - memcpy(buf->msg, payload, nof_bytes); - buf->N_bytes = nof_bytes; - buf->set_timestamp(); - pdcp->write_pdu_bcch_dlsch(buf); + if (buf) { + memcpy(buf->msg, payload, nof_bytes); + buf->N_bytes = nof_bytes; + buf->set_timestamp(); + pdcp->write_pdu_bcch_dlsch(buf); + } else { + rlc_log->error("Fatal error: Out of buffers from the pool in write_pdu_bcch_dlsch()\n"); + } } void rlc::write_pdu_pcch(uint8_t *payload, uint32_t nof_bytes) @@ -209,10 +217,14 @@ void rlc::write_pdu_pcch(uint8_t *payload, uint32_t nof_bytes) rlc_log->info_hex(payload, nof_bytes, "PCCH message received."); dl_tput_bytes[0] += nof_bytes; byte_buffer_t *buf = pool_allocate; - memcpy(buf->msg, payload, nof_bytes); - buf->N_bytes = nof_bytes; - buf->set_timestamp(); - pdcp->write_pdu_pcch(buf); + if (buf) { + memcpy(buf->msg, payload, nof_bytes); + buf->N_bytes = nof_bytes; + buf->set_timestamp(); + pdcp->write_pdu_pcch(buf); + } else { + rlc_log->error("Fatal error: Out of buffers from the pool in write_pdu_pcch()\n"); + } } /******************************************************************************* @@ -281,6 +293,7 @@ void rlc::add_bearer(uint32_t lcid, srslte_rlc_config_t cnfg) bool rlc::valid_lcid(uint32_t lcid) { if(lcid >= SRSLTE_N_RADIO_BEARERS) { + rlc_log->warning("Invalid LCID=%d\n", lcid); return false; } else if(!rlc_array[lcid].active()) { return false;