Harald Welte has submitted this change and it was merged.

Change subject: trxcon/l1ctl_link.c: allocate msgb after its length is read
......................................................................


trxcon/l1ctl_link.c: allocate msgb after its length is read

Change-Id: I2b941c5ed91097c4ed2d859634bbe89f44546061
---
M src/host/trxcon/l1ctl_link.c
1 file changed, 8 insertions(+), 10 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/host/trxcon/l1ctl_link.c b/src/host/trxcon/l1ctl_link.c
index 0fa3efe..20cb70c 100644
--- a/src/host/trxcon/l1ctl_link.c
+++ b/src/host/trxcon/l1ctl_link.c
@@ -75,19 +75,10 @@
        uint16_t len;
        int rc;
 
-       /* Allocate a new msg */
-       msg = msgb_alloc_headroom(L1CTL_LENGTH + L1CTL_HEADROOM,
-               L1CTL_HEADROOM, "l1ctl_rx_msg");
-       if (!msg) {
-               LOGP(DL1D, LOGL_ERROR, "Failed to allocate msg\n");
-               return -ENOMEM;
-       }
-
        /* Attempt to read from socket */
        rc = read(bfd->fd, &len, L1CTL_MSG_LEN_FIELD);
        if (rc < L1CTL_MSG_LEN_FIELD) {
                LOGP(DL1D, LOGL_NOTICE, "L1CTL has lost connection\n");
-               msgb_free(msg);
                if (rc >= 0)
                        rc = -EIO;
                l1ctl_link_close_conn(l1l);
@@ -98,10 +89,17 @@
        len = ntohs(len);
        if (len > L1CTL_LENGTH) {
                LOGP(DL1D, LOGL_ERROR, "Length is too big: %u\n", len);
-               msgb_free(msg);
                return -EINVAL;
        }
 
+       /* Allocate a new msg */
+       msg = msgb_alloc_headroom(L1CTL_LENGTH + L1CTL_HEADROOM,
+               L1CTL_HEADROOM, "l1ctl_rx_msg");
+       if (!msg) {
+               LOGP(DL1D, LOGL_ERROR, "Failed to allocate msg\n");
+               return -ENOMEM;
+       }
+
        msg->l1h = msgb_put(msg, len);
        rc = read(bfd->fd, msg->l1h, msgb_l1len(msg));
        if (rc != len) {

-- 
To view, visit https://gerrit.osmocom.org/7209
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2b941c5ed91097c4ed2d859634bbe89f44546061
Gerrit-PatchSet: 2
Gerrit-Project: osmocom-bb
Gerrit-Branch: fixeria/trx
Gerrit-Owner: Vadim Yanitskiy <axilira...@gmail.com>
Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org>
Gerrit-Reviewer: Jenkins Builder

Reply via email to