rlc: fix memleak in queue_rx_pdu

* alternative to #3141
* use byte_buffer as queue element
master
Andre Puschmann 3 years ago
parent deb157daa2
commit 1c3a03cb2b

@ -226,16 +226,15 @@ public:
if (!suspended) { if (!suspended) {
return false; return false;
} }
pdu_t p; unique_byte_buffer_t rx_pdu;
// Do not block // Do not block
while (rx_pdu_resume_queue.try_pop(p)) { while (rx_pdu_resume_queue.try_pop(rx_pdu)) {
write_pdu(p.payload, p.nof_bytes); write_pdu(rx_pdu->msg, rx_pdu->N_bytes);
free(p.payload);
} }
unique_byte_buffer_t s; unique_byte_buffer_t tx_sdu;
while (tx_sdu_resume_queue.try_pop(s)) { while (tx_sdu_resume_queue.try_pop(tx_sdu)) {
write_sdu(std::move(s)); write_sdu(std::move(tx_sdu));
} }
suspended = false; suspended = false;
return true; return true;
@ -288,13 +287,22 @@ private:
// Enqueues the Rx PDU in the resume queue // Enqueues the Rx PDU in the resume queue
void queue_rx_pdu(uint8_t* payload, uint32_t nof_bytes) void queue_rx_pdu(uint8_t* payload, uint32_t nof_bytes)
{ {
pdu_t p = {}; unique_byte_buffer_t rx_pdu = srsran::make_byte_buffer();
p.nof_bytes = nof_bytes; if (rx_pdu == nullptr) {
p.payload = (uint8_t*)malloc(nof_bytes); srslog::fetch_basic_logger("RLC").warning("Couldn't allocate PDU in %s().", __FUNCTION__);
memcpy(p.payload, payload, nof_bytes); return;
}
if (rx_pdu->get_tailroom() < nof_bytes) {
srslog::fetch_basic_logger("RLC").warning("Not enough space to store PDU.");
return;
}
memcpy(rx_pdu->msg, payload, nof_bytes);
rx_pdu->N_bytes = nof_bytes;
// Do not block ever // Do not block ever
if (!rx_pdu_resume_queue.try_push(p)) { if (!rx_pdu_resume_queue.try_push(std::move(rx_pdu))) {
srslog::fetch_basic_logger("RLC").warning("Dropping SDUs while bearer suspended."); srslog::fetch_basic_logger("RLC").warning("Dropping SDUs while bearer suspended.");
return; return;
} }
@ -310,12 +318,7 @@ private:
} }
} }
typedef struct { static_blocking_queue<unique_byte_buffer_t, 256> rx_pdu_resume_queue;
uint8_t* payload;
uint32_t nof_bytes;
} pdu_t;
static_blocking_queue<pdu_t, 256> rx_pdu_resume_queue;
static_blocking_queue<unique_byte_buffer_t, 256> tx_sdu_resume_queue; static_blocking_queue<unique_byte_buffer_t, 256> tx_sdu_resume_queue;
}; };

Loading…
Cancel
Save