[PATCH] osmo-mgw[master]: client: use heap to store mgcp_response

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

dexter gerrit-no-reply at lists.osmocom.org
Wed Jan 31 16:42:31 UTC 2018


Review at  https://gerrit.osmocom.org/6222

client: use heap to store mgcp_response

The struct that holds the parsing results of the MGCP response is
allocated on the stack. However, it would make sense to allocate
the struct dynamically on the heap. This also would provide a
talloc context that is in reach on most places of the code.

- Allocate struct mgcp_response dynamically in mgcp_client_rx()

- Use struct mgcp_response as talloc context for temporary
  allocated memory while parsing the response.

Change-Id: I5099abe68b580c75b47bc797bf93f01084f0c4db
---
M src/libosmo-mgcp-client/mgcp_client.c
1 file changed, 22 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/22/6222/1

diff --git a/src/libosmo-mgcp-client/mgcp_client.c b/src/libosmo-mgcp-client/mgcp_client.c
index efe1d1f..ea7ac36 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -257,7 +257,7 @@
 
 	/* Since this functions performs a destructive parsing, we create a
 	 * local copy of the body data */
-	data = talloc_zero_size(NULL, strlen(r->body)+1);
+	data = talloc_zero_size(r, strlen(r->body)+1);
 	OSMO_ASSERT(data);
 	data_ptr = data;
 	osmo_strlcpy(data, r->body, strlen(r->body));
@@ -336,7 +336,7 @@
 
 	/* Since this functions performs a destructive parsing, we create a
 	 * local copy of the body data */
-	data = talloc_zero_size(NULL, strlen(r->body)+1);
+	data = talloc_zero_size(r, strlen(r->body)+1);
 	OSMO_ASSERT(data);
 	data_ptr = data;
 	osmo_strlcpy(data, r->body, strlen(r->body));
@@ -410,32 +410,42 @@
  */
 int mgcp_client_rx(struct mgcp_client *mgcp, struct msgb *msg)
 {
-	struct mgcp_response r = { 0 };
+	struct mgcp_response *r;
 	struct mgcp_response_pending *pending;
 	int rc;
 
-	rc = mgcp_response_parse_head(&r, msg);
+	r = talloc_zero(mgcp, struct mgcp_response);
+	OSMO_ASSERT(r);
+
+	rc = mgcp_response_parse_head(r, msg);
 	if (rc) {
 		LOGP(DLMGCP, LOGL_ERROR, "Cannot parse MGCP response (head)\n");
-		return -1;
+		rc = 1;
+		goto error;
 	}
 
-	rc = parse_head_params(&r);
+	rc = parse_head_params(r);
 	if (rc) {
 		LOGP(DLMGCP, LOGL_ERROR, "Cannot parse MGCP response (head parameters)\n");
-		return -1;
+		rc = 1;
+		goto error;
 	}
 
-	pending = mgcp_client_response_pending_get(mgcp, r.head.trans_id);
+	pending = mgcp_client_response_pending_get(mgcp, r->head.trans_id);
 	if (!pending) {
 		LOGP(DLMGCP, LOGL_ERROR,
 		     "Cannot find matching MGCP transaction for trans_id %d\n",
-		     r.head.trans_id);
-		return -ENOENT;
+		     r->head.trans_id);
+		rc = -ENOENT;
+		goto error;
 	}
 
-	mgcp_client_handle_response(mgcp, pending, &r);
-	return 0;
+	mgcp_client_handle_response(mgcp, pending, r);
+	rc = 0;
+
+error:
+	talloc_free(r);
+	return rc;
 }
 
 static int mgcp_do_read(struct osmo_fd *fd)

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5099abe68b580c75b47bc797bf93f01084f0c4db
Gerrit-PatchSet: 1
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: dexter <pmaier at sysmocom.de>



More information about the gerrit-log mailing list