aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo-bts-sysmo/l1_fwd_main.c
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2015-03-28 18:31:10 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2015-03-28 18:31:10 +0100
commitf869a95f3b81d281405e3fc3026e1d0d53174082 (patch)
treebe55f619c8932bd9130af5ecd5e0e32aeda386d2 /src/osmo-bts-sysmo/l1_fwd_main.c
parent0ddd4b6c25dcb1cf85809b190afd6ac4d95890ea (diff)
write_queue: Check the result of osmo_wqueue_enqueue and free
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.
Diffstat (limited to 'src/osmo-bts-sysmo/l1_fwd_main.c')
-rw-r--r--src/osmo-bts-sysmo/l1_fwd_main.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/osmo-bts-sysmo/l1_fwd_main.c b/src/osmo-bts-sysmo/l1_fwd_main.c
index cb05e15..92d2ea4 100644
--- a/src/osmo-bts-sysmo/l1_fwd_main.c
+++ b/src/osmo-bts-sysmo/l1_fwd_main.c
@@ -77,7 +77,12 @@ int l1if_handle_l1prim(int wq, struct femtol1_hdl *fl1h, struct msgb *msg)
struct l1fwd_hdl *l1fh = fl1h->priv;
/* Enqueue message to UDP socket */
- return osmo_wqueue_enqueue(&l1fh->udp_wq[wq], msg);
+ if (osmo_wqueue_enqueue(&l1fh->udp_wq[wq], msg) != 0) {
+ LOGP(DL1C, LOGL_ERROR, "Write queue %d full. dropping msg\n", wq);
+ msgb_free(msg);
+ return -EAGAIN;
+ }
+ return 0;
}
/* callback when there's a new SYS primitive coming in from the HW */
@@ -86,7 +91,12 @@ int l1if_handle_sysprim(struct femtol1_hdl *fl1h, struct msgb *msg)
struct l1fwd_hdl *l1fh = fl1h->priv;
/* Enqueue message to UDP socket */
- return osmo_wqueue_enqueue(&l1fh->udp_wq[MQ_SYS_WRITE], msg);
+ if (osmo_wqueue_enqueue(&l1fh->udp_wq[MQ_SYS_WRITE], msg) != 0) {
+ LOGP(DL1C, LOGL_ERROR, "MQ_SYS_WRITE ful. dropping msg\n");
+ msgb_free(msg);
+ return -EAGAIN;
+ }
+ return 0;
}
@@ -121,9 +131,13 @@ static int udp_read_cb(struct osmo_fd *ofd)
ofd->priv_nr);
/* put the message into the right queue */
- rc = osmo_wqueue_enqueue(&fl1h->write_q[ofd->priv_nr], msg);
-
- return rc;
+ if (osmo_wqueue_enqueue(&fl1h->write_q[ofd->priv_nr], msg) != 0) {
+ LOGP(DL1C, LOGL_ERROR, "Write queue %d full. dropping msg\n",
+ ofd->priv_nr);
+ msgb_free(msg);
+ return -EAGAIN;
+ }
+ return 0;
}
/* callback when we can write to the UDP socket */