transport: af-mctp: Assign out-params on success in *_recv()
More specifically, don't assign to out-params while it's possible we can
fail.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Ib848d1b363288e5f0b76885ff96500d09ddfc2bf
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9662f8b..b63c098 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,7 @@
3. pdr : Stabilize pldm_entity_association_tree_add_entity()
4. pdr: Stabilise pldm_entity_association_tree_find_with_locality()
5. pdr: Stabilize pldm_entity_node_get_remote_container_id()
+6. transport: af-mctp: Assign out-params on success in \*\_recv()
### Removed
diff --git a/src/transport/af-mctp.c b/src/transport/af-mctp.c
index 8c09658..8c7046b 100644
--- a/src/transport/af-mctp.c
+++ b/src/transport/af-mctp.c
@@ -87,6 +87,7 @@
struct pldm_transport_af_mctp *af_mctp = transport_to_af_mctp(t);
mctp_eid_t eid = 0;
ssize_t length;
+ void *msg;
int rc;
rc = pldm_transport_af_mctp_get_eid(af_mctp, tid, &eid);
@@ -99,13 +100,14 @@
return PLDM_REQUESTER_RECV_FAIL;
}
- *pldm_msg = malloc(length);
- length = recv(af_mctp->socket, *pldm_msg, length, MSG_TRUNC);
+ msg = malloc(length);
+ length = recv(af_mctp->socket, msg, length, MSG_TRUNC);
if (length < (ssize_t)sizeof(struct pldm_msg_hdr)) {
- free(*pldm_msg);
+ free(msg);
return PLDM_REQUESTER_INVALID_RECV_LEN;
}
+ *pldm_msg = msg;
*msg_len = length;
return PLDM_REQUESTER_SUCCESS;