Commit 885a029a authored by Robert Schmidt's avatar Robert Schmidt

Fix memory leaks in do_NR_DLInformationTransfer()

parent a4c75620
...@@ -948,41 +948,36 @@ uint8_t do_RRCSetupComplete(uint8_t Mod_id, uint8_t *buffer, size_t buffer_size, ...@@ -948,41 +948,36 @@ uint8_t do_RRCSetupComplete(uint8_t Mod_id, uint8_t *buffer, size_t buffer_size,
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
uint8_t uint8_t do_NR_DLInformationTransfer(uint8_t Mod_id,
do_NR_DLInformationTransfer( uint8_t *buffer,
uint8_t Mod_id, size_t buffer_len,
uint8_t **buffer, uint8_t transaction_id,
uint8_t transaction_id, uint32_t pdu_length,
uint32_t pdu_length, uint8_t *pdu_buffer)
uint8_t *pdu_buffer
)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
{ {
ssize_t encoded; NR_DL_DCCH_Message_t dl_dcch_msg = {0};
NR_DL_DCCH_Message_t dl_dcch_msg={0}; dl_dcch_msg.message.present = NR_DL_DCCH_MessageType_PR_c1;
dl_dcch_msg.message.present = NR_DL_DCCH_MessageType_PR_c1; asn1cCalloc(dl_dcch_msg.message.choice.c1, c1);
asn1cCalloc(dl_dcch_msg.message.choice.c1, c1); c1->present = NR_DL_DCCH_MessageType__c1_PR_dlInformationTransfer;
c1->present = NR_DL_DCCH_MessageType__c1_PR_dlInformationTransfer;
asn1cCalloc(c1->choice.dlInformationTransfer, infoTransfer);
asn1cCalloc(c1->choice.dlInformationTransfer, infoTransfer); infoTransfer->rrc_TransactionIdentifier = transaction_id;
infoTransfer->rrc_TransactionIdentifier = transaction_id; infoTransfer->criticalExtensions.present = NR_DLInformationTransfer__criticalExtensions_PR_dlInformationTransfer;
infoTransfer->criticalExtensions.present =
NR_DLInformationTransfer__criticalExtensions_PR_dlInformationTransfer; asn1cCalloc(infoTransfer->criticalExtensions.choice.dlInformationTransfer, dlInfoTransfer);
asn1cCalloc(dlInfoTransfer->dedicatedNAS_Message, msg);
asn1cCalloc(infoTransfer->criticalExtensions.choice.dlInformationTransfer, dlInfoTransfer); // we will free the caller buffer, that is ok in the present code logic (else it will leak memory) but not natural,
asn1cCalloc(dlInfoTransfer->dedicatedNAS_Message,msg); // comprehensive code design
// we will free the caller buffer, that is ok in the present code logic (else it will leak memory) but not natural, msg->buf = pdu_buffer;
// comprehensive code design msg->size = pdu_length;
msg->buf = pdu_buffer;
msg->size = pdu_length; asn_enc_rval_t r = uper_encode_to_buffer(&asn_DEF_NR_DL_DCCH_Message, NULL, (void *)&dl_dcch_msg, buffer, buffer_len);
AssertFatal(r.encoded > 0, "ASN1 message encoding failed (%s, %ld)!\n", "DLInformationTransfer", r.encoded);
encoded = uper_encode_to_new_buffer (&asn_DEF_NR_DL_DCCH_Message, NULL, (void *) &dl_dcch_msg, (void **)buffer); ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NR_DL_DCCH_Message, &dl_dcch_msg);
AssertFatal(encoded > 0,"ASN1 message encoding failed (%s, %ld)!\n", LOG_D(NR_RRC, "DLInformationTransfer Encoded %zd bytes\n", r.encoded);
"DLInformationTransfer", encoded); // for (int i=0;i<encoded;i++) printf("%02x ",(*buffer)[i]);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NR_DL_DCCH_Message,&dl_dcch_msg ); return r.encoded;
LOG_D(NR_RRC,"DLInformationTransfer Encoded %zd bytes\n", encoded);
//for (int i=0;i<encoded;i++) printf("%02x ",(*buffer)[i]);
return encoded;
} }
uint8_t do_NR_ULInformationTransfer(uint8_t **buffer, uint32_t pdu_length, uint8_t *pdu_buffer) { uint8_t do_NR_ULInformationTransfer(uint8_t **buffer, uint32_t pdu_length, uint8_t *pdu_buffer) {
......
...@@ -128,14 +128,12 @@ uint8_t do_NR_RRCReconfigurationComplete( ...@@ -128,14 +128,12 @@ uint8_t do_NR_RRCReconfigurationComplete(
const uint8_t Transaction_id const uint8_t Transaction_id
); );
uint8_t uint8_t do_NR_DLInformationTransfer(uint8_t Mod_id,
do_NR_DLInformationTransfer( uint8_t *buffer,
uint8_t Mod_id, size_t buffer_len,
uint8_t **buffer, uint8_t transaction_id,
uint8_t transaction_id, uint32_t pdu_length,
uint32_t pdu_length, uint8_t *pdu_buffer);
uint8_t *pdu_buffer
);
uint8_t do_NR_ULInformationTransfer(uint8_t **buffer, uint8_t do_NR_ULInformationTransfer(uint8_t **buffer,
uint32_t pdu_length, uint32_t pdu_length,
......
...@@ -588,7 +588,7 @@ int rrc_gNB_process_NGAP_DOWNLINK_NAS(MessageDef *msg_p, instance_t instance, mu ...@@ -588,7 +588,7 @@ int rrc_gNB_process_NGAP_DOWNLINK_NAS(MessageDef *msg_p, instance_t instance, mu
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
{ {
uint32_t length; uint32_t length;
uint8_t *buffer; uint8_t buffer[4096];
protocol_ctxt_t ctxt = {0}; protocol_ctxt_t ctxt = {0};
ngap_downlink_nas_t *req = &NGAP_DOWNLINK_NAS(msg_p); ngap_downlink_nas_t *req = &NGAP_DOWNLINK_NAS(msg_p);
rrc_gNB_ue_context_t *ue_context_p = rrc_gNB_get_ue_context(RC.nrrrc[instance], req->gNB_ue_ngap_id); rrc_gNB_ue_context_t *ue_context_p = rrc_gNB_get_ue_context(RC.nrrrc[instance], req->gNB_ue_ngap_id);
...@@ -611,7 +611,12 @@ int rrc_gNB_process_NGAP_DOWNLINK_NAS(MessageDef *msg_p, instance_t instance, mu ...@@ -611,7 +611,12 @@ int rrc_gNB_process_NGAP_DOWNLINK_NAS(MessageDef *msg_p, instance_t instance, mu
PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, GNB_FLAG_YES, UE->rrc_ue_id, 0, 0); PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, GNB_FLAG_YES, UE->rrc_ue_id, 0, 0);
/* Create message for PDCP (DLInformationTransfer_t) */ /* Create message for PDCP (DLInformationTransfer_t) */
length = do_NR_DLInformationTransfer(instance, &buffer, rrc_gNB_get_next_transaction_identifier(instance), req->nas_pdu.length, req->nas_pdu.buffer); length = do_NR_DLInformationTransfer(instance,
buffer,
sizeof(buffer),
rrc_gNB_get_next_transaction_identifier(instance),
req->nas_pdu.length,
req->nas_pdu.buffer);
LOG_DUMPMSG(NR_RRC, DEBUG_RRC, buffer, length, "[MSG] RRC DL Information Transfer\n"); LOG_DUMPMSG(NR_RRC, DEBUG_RRC, buffer, length, "[MSG] RRC DL Information Transfer\n");
/* /*
* switch UL or DL NAS message without RRC piggybacked to SRB2 if active. * switch UL or DL NAS message without RRC piggybacked to SRB2 if active.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment