Change in ...osmo-pcu[master]: osmobts_sock.cpp: pcu_sock_read(): use stack buffer, not heap

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/gerrit-log@lists.osmocom.org/.

fixeria gerrit-no-reply at lists.osmocom.org
Fri Aug 23 15:50:00 UTC 2019


fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-pcu/+/15279


Change subject: osmobts_sock.cpp: pcu_sock_read(): use stack buffer, not heap
......................................................................

osmobts_sock.cpp: pcu_sock_read(): use stack buffer, not heap

We don't really need to use the message buffer (on heap), because
it's never getting passed to pcu_rx(). Let's use a buffer on stack.

Change-Id: I4cb8ca80513df7b71e1438da2e82799be6be1fa0
---
M src/osmobts_sock.cpp
1 file changed, 3 insertions(+), 15 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/79/15279/1

diff --git a/src/osmobts_sock.cpp b/src/osmobts_sock.cpp
index 1072229..3fa6d15 100644
--- a/src/osmobts_sock.cpp
+++ b/src/osmobts_sock.cpp
@@ -139,17 +139,10 @@
 static int pcu_sock_read(struct osmo_fd *bfd)
 {
 	struct pcu_sock_state *state = (struct pcu_sock_state *)bfd->data;
-	struct gsm_pcu_if *pcu_prim;
-	struct msgb *msg;
+	struct gsm_pcu_if pcu_prim;
 	int rc;
 
-	msg = msgb_alloc(sizeof(*pcu_prim), "pcu_sock_rx");
-	if (!msg)
-		return -ENOMEM;
-
-	pcu_prim = (struct gsm_pcu_if *) msg->tail;
-
-	rc = recv(bfd->fd, msg->tail, msgb_tailroom(msg), 0);
+	rc = recv(bfd->fd, &pcu_prim, sizeof(pcu_prim), 0);
 	if (rc == 0)
 		goto close;
 
@@ -159,16 +152,11 @@
 		goto close;
 	}
 
-	rc = pcu_rx(pcu_prim->msg_type, pcu_prim);
-
-	/* as we always synchronously process the message in pcu_rx() and
-	 * its callbacks, we can free the message here. */
-	msgb_free(msg);
+	rc = pcu_rx(pcu_prim.msg_type, &pcu_prim);
 
 	return rc;
 
 close:
-	msgb_free(msg);
 	pcu_sock_close(state, 1);
 	return -1;
 }

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-pcu/+/15279
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Change-Id: I4cb8ca80513df7b71e1438da2e82799be6be1fa0
Gerrit-Change-Number: 15279
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <axilirator at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190823/7a290fa9/attachment.htm>


More information about the gerrit-log mailing list