[PATCH 1/3] write_queue: Check the result of osmo_wqueue_enqueue and free

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/osmocom-net-gprs@lists.osmocom.org/.

Holger Hans Peter Freyther holger at moiji-mobile.com
Fri May 22 02:50:36 UTC 2015


The write_queue is designed to have a maximum amount of pending
messages and will refuse to take new messages when it has been
reached. The caller can decide if it wants to flush the queue
and add the message again, create a log. But in all cases the
ownership of the msgb has not been transferred. Fix the potential
memory leak in the failure situation.
---
 src/openbts_sock.cpp |  5 ++++-
 src/sysmo_l1_if.c    | 10 ++++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/openbts_sock.cpp b/src/openbts_sock.cpp
index 2d9cae4..5e6f16c 100644
--- a/src/openbts_sock.cpp
+++ b/src/openbts_sock.cpp
@@ -79,7 +79,10 @@ struct l1fwd_hdl *l1fh = talloc_zero(NULL, struct l1fwd_hdl);
 
 int pcu_sock_send(struct msgb *msg)
 {
-	osmo_wqueue_enqueue(&l1fh->udp_wq, msg);
+	if (osmo_wqueue_enqueue(&l1fh->udp_wq, msg) != 0) {
+		LOGP(DPCU, LOGL_ERROR, "PCU write queue full. Dropping message.\n");
+		msgb_free(msg);
+	}
 	return 0;
 }
 
diff --git a/src/sysmo_l1_if.c b/src/sysmo_l1_if.c
index bef680e..c0721b8 100644
--- a/src/sysmo_l1_if.c
+++ b/src/sysmo_l1_if.c
@@ -36,7 +36,10 @@ static int l1if_req_pdch(struct femtol1_hdl *fl1h, struct msgb *msg)
 {
 	struct osmo_wqueue *wqueue = &fl1h->write_q[MQ_PDTCH_WRITE];
 
-	osmo_wqueue_enqueue(wqueue, msg);
+	if (osmo_wqueue_enqueue(wqueue, msg) != 0) {
+		LOGP(DL1IF, LOGL_ERROR, "PDTCH queue full. dropping message.\n");
+		msgb_free(msg);
+	}
 
 	return 0;
 }
@@ -324,7 +327,10 @@ int l1if_pdch_req(void *obj, uint8_t ts, int is_ptcch, uint32_t fn,
 
 
 	/* transmit */
-	osmo_wqueue_enqueue(&fl1h->write_q[MQ_PDTCH_WRITE], msg);
+	if (osmo_wqueue_enqueue(&fl1h->write_q[MQ_PDTCH_WRITE], msg) != 0) {
+		LOGP(DL1IF, LOGL_ERROR, "PDTCH queue full. dropping message.\n");
+		msgb_free(msg);
+	}
 
 	return 0;
 }
-- 
2.3.5




More information about the osmocom-net-gprs mailing list