Change in libosmocore[master]: libosmocore: change the memory management of NS2

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/.

lynxis lazus gerrit-no-reply at lists.osmocom.org
Sun Oct 25 23:38:14 UTC 2020


lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/20912 )


Change subject: libosmocore: change the memory management of NS2
......................................................................

libosmocore: change the memory management of NS2

Until now NS2 always free'd it's own memory. Even when the msg
was sent as primitive to the upper layer.
Change the memory ownership when sending a primitive to the upper layer.
The upper layer has to free the msg buffer.

Merge together with: I180433735bfbb3375c41318d7a7709d5845199ba (osmo-pcu)
Change-Id: If6f432ec29daa3e1833f62b5f4d29db3e1eb7cc0

Change-Id: Id844d7acbcab102a7dc472d608a5e97a748ecb43
---
M src/gb/gprs_ns2_vc_fsm.c
1 file changed, 30 insertions(+), 12 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/12/20912/1

diff --git a/src/gb/gprs_ns2_vc_fsm.c b/src/gb/gprs_ns2_vc_fsm.c
index d13f1ce..bbe6661 100644
--- a/src/gb/gprs_ns2_vc_fsm.c
+++ b/src/gb/gprs_ns2_vc_fsm.c
@@ -459,8 +459,10 @@
 	struct osmo_gprs_ns2_prim nsp = {};
 	uint16_t bvci;
 
-	if (msgb_l2len(msg) < sizeof(*nsh) + 3)
+	if (msgb_l2len(msg) < sizeof(*nsh) + 3) {
+		msgb_free(msg);
 		return;
+	}
 
 	/* TODO: 7.1: For an IP sub-network, an NS-UNITDATA PDU
 	 * for a PTP BVC may indicate a request to change the IP endpoint
@@ -488,6 +490,7 @@
 {
 	struct gprs_ns2_vc_priv *priv = fi->priv;
 	struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi);
+	struct msgb *msg = data;
 
 	switch (event) {
 	case GPRS_NS2_EV_RESET:
@@ -520,22 +523,31 @@
 			recv_test_procedure(fi);
 		break;
 	case GPRS_NS2_EV_UNITDATA:
+		/* UNITDATA has to handle the release of msg.
+		 * If send upwards (gprs_ns2_recv_unitdata) it must NOT free
+		 * the msg, the upper layer has to do it.
+		 * Otherwise the msg must be freed.
+		 */
 		switch (fi->state) {
 		case GPRS_NS2_ST_BLOCKED:
 			/* 7.2.1: the BLOCKED_ACK might be lost */
-			if (priv->initiater)
-				gprs_ns2_recv_unitdata(fi, data);
-			else
-				ns2_tx_status(priv->nsvc,
-					      NS_CAUSE_NSVC_BLOCKED,
-					      0, data);
+			if (priv->initiater) {
+				gprs_ns2_recv_unitdata(fi, msg);
+				return;
+			}
+
+			ns2_tx_status(priv->nsvc,
+				      NS_CAUSE_NSVC_BLOCKED,
+				      0, msg);
 			break;
 		/* ALIVE can receive UNITDATA if the ALIVE_ACK is lost */
 		case GPRS_NS2_ST_ALIVE:
 		case GPRS_NS2_ST_UNBLOCKED:
-			gprs_ns2_recv_unitdata(fi, data);
-			break;
+			gprs_ns2_recv_unitdata(fi, msg);
+			return;
 		}
+
+		msgb_free(msg);
 		break;
 	}
 }
@@ -605,6 +617,7 @@
 {
 	struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *) msg->l2h;
 	struct osmo_fsm_inst *fi = nsvc->fi;
+	int rc = 0;
 	uint8_t cause;
 
 	/* TODO: 7.2: on UNBLOCK/BLOCK: check if NS-VCI is correct,
@@ -614,7 +627,8 @@
 
 	if (gprs_ns2_validate(nsvc, nsh->pdu_type, msg, tp, &cause)) {
 		if (nsh->pdu_type != NS_PDUT_STATUS) {
-			return ns2_tx_status(nsvc, cause, 0, msg);
+			rc = ns2_tx_status(nsvc, cause, 0, msg);
+			goto out;
 		}
 	}
 
@@ -644,15 +658,19 @@
 		osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_ALIVE_ACK, tp);
 		break;
 	case NS_PDUT_UNITDATA:
+		/* UNITDATA have to free msg because it might send the msg layer upwards */
 		osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_UNITDATA, msg);
-		break;
+		return 0;
 	default:
 		LOGP(DLNS, LOGL_ERROR, "NSEI=%u Rx unknown NS PDU type %s\n", nsvc->nse->nsei,
 			get_value_string(gprs_ns_pdu_strings, nsh->pdu_type));
 		return -EINVAL;
 	}
 
-	return 0;
+out:
+	msgb_free(msg);
+
+	return rc;
 }
 
 /*! is the given NS-VC unblocked? */

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Id844d7acbcab102a7dc472d608a5e97a748ecb43
Gerrit-Change-Number: 20912
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <lynxis at fe80.eu>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20201025/4bdeb984/attachment.htm>


More information about the gerrit-log mailing list