Hello Harald Welte, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/6222

to look at the new patch set (#4).

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

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: newpatchset
Gerrit-Change-Id: I5099abe68b580c75b47bc797bf93f01084f0c4db
Gerrit-PatchSet: 4
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: dexter <pma...@sysmocom.de>
Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org>
Gerrit-Reviewer: Jenkins Builder

Reply via email to