Fix memory leakage 98/6898/1
authorwansu.yoo <wansu.yoo@samsung.com>
Thu, 21 Oct 2021 01:29:37 +0000 (10:29 +0900)
committerwansu.yoo <wansu.yoo@samsung.com>
Thu, 21 Oct 2021 01:47:45 +0000 (10:47 +0900)
- Remove unused heap memory allocation to prevent memory leakage.
- Add ASN_STRUCT_FREE to release allocated asn structure memory.
- Add free to release allocated heap memory.

Signed-off-by: wansu.yoo <wansu.yoo@samsung.com>
Change-Id: Ibbc2a0ae8b7b4af278a0712069e3e0c16d9d4bc4

e2sim/e2sm_examples/kpm_e2sm/src/kpm/encode_kpm.cpp
e2sim/e2sm_examples/kpm_e2sm/src/kpm/kpm_callbacks.cpp
e2sim/src/base/e2sim.cpp
e2sim/src/encoding/encode_e2apv1.cpp
e2sim/src/messagerouting/e2ap_message_handler.cpp

index b3a0465..764c69b 100755 (executable)
@@ -195,18 +195,6 @@ void encode_e2sm_kpm_indication_header(E2SM_KPM_IndicationHeader_t *ihead, uint8
   //  long fqival = 9;
   //  long qcival = 9;
   
-  OCTET_STRING_t *sst = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
-  sst->size = 6;
-  sst->buf = (uint8_t*)calloc(1,6);
-  memcpy(sst->buf,sst_buf,sst->size);
-  
-  
-  OCTET_STRING_t *sds = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
-  sds->size = 3;
-  sds->buf = (uint8_t*)calloc(1,3);
-  memcpy(sds->buf, sd_buf, sds->size);
-  
-  
   SNSSAI_t *snssai = (SNSSAI_t*)calloc(1, sizeof(SNSSAI_t));
   ASN_STRUCT_RESET(asn_DEF_SNSSAI,snssai);
   snssai->sST.buf = (uint8_t*)calloc(1,1);
@@ -277,6 +265,7 @@ void encode_e2sm_kpm_indication_header(E2SM_KPM_IndicationHeader_t *ihead, uint8
   ind_header->nRCGI = (NRCGI*)calloc(1,sizeof(NRCGI));
   ind_header->nRCGI->pLMN_Identity = *plmnid;
   ind_header->nRCGI->nRCellIdentity = *nrcellid;
+  if (nrcellid) free(nrcellid);
   
   ind_header->pLMN_Identity = plmnid;
   //  memcpy(ind_header->fiveQI, &fqival, 4);
@@ -288,6 +277,7 @@ void encode_e2sm_kpm_indication_header(E2SM_KPM_IndicationHeader_t *ihead, uint8
   ind_header->gNB_Name = (GNB_Name*)calloc(1,sizeof(GNB_Name));
   ind_header->gNB_Name->present = GNB_Name_PR_gNB_CU_UP_Name;
   ind_header->gNB_Name->choice.gNB_CU_UP_Name = *cuupname;
+  if (cuupname) free(cuupname);
 
  
   ind_header->global_GNB_ID = (GlobalgNB_ID*)calloc(1,sizeof(GlobalgNB_ID));
@@ -303,6 +293,7 @@ void encode_e2sm_kpm_indication_header(E2SM_KPM_IndicationHeader_t *ihead, uint8
   
   ihead->present = E2SM_KPM_IndicationHeader_PR_indicationHeader_Format1;
   ihead->choice.indicationHeader_Format1 = *ind_header;
+  if (ind_header) free(ind_header);
   
   xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationHeader, ihead);
   
@@ -347,10 +338,13 @@ void encode_kpm_ocuup_user_level(RAN_Container_t *ranco,
   NRCGI *nrcgi = (NRCGI*)calloc(1,sizeof(NRCGI));
   nrcgi->pLMN_Identity = *plmnidstr;
   nrcgi->nRCellIdentity = *nrcellid;
+  if (plmnidstr) free(plmnidstr);
+  if (nrcellid) free(nrcellid);
  
   printf("enc3\n");
   
   report_item->nRCGI = *nrcgi;
+  if (nrcgi) free(nrcgi);
 
   CU_UP_Usage_Report_UeResourceReportItem *ue_report_item =
     (CU_UP_Usage_Report_UeResourceReportItem*)calloc(1,sizeof(CU_UP_Usage_Report_UeResourceReportItem));
@@ -467,6 +461,7 @@ void encode_kpm_ocuup_user_level(RAN_Container_t *ranco,
   ue_report_item->c_RNTI = *crnti;
   ue_report_item->pDCPBytesDL = bytesdl;
   ue_report_item->pDCPBytesUL = bytesul;
+  if (crnti) free(crnti);
 
 
   ASN_SEQUENCE_ADD(&report_item->ueResourceReportList.list, ue_report_item);  
@@ -474,6 +469,7 @@ void encode_kpm_ocuup_user_level(RAN_Container_t *ranco,
   ranco->timestamp = *ts;
   ranco->reportContainer.present = RAN_Container__reportContainer_PR_oCU_UP_UE;
   ASN_SEQUENCE_ADD(&ranco->reportContainer.choice.oCU_UP_UE.cellResourceReportList.list, report_item);
+  if (ts) free(ts);
 
   xer_fprint(stderr, &asn_DEF_RAN_Container, ranco);
 
@@ -516,10 +512,13 @@ void encode_kpm_ocucp_user_level(RAN_Container_t *ranco,
   NRCGI *nrcgi = (NRCGI*)calloc(1,sizeof(NRCGI));
   nrcgi->pLMN_Identity = *plmnidstr;
   nrcgi->nRCellIdentity = *nrcellid;
+  if (plmnidstr) free(plmnidstr);
+  if (nrcellid) free(nrcellid);
  
   printf("enc3\n");
   
   report_item->nRCGI = *nrcgi;
+  if (nrcgi) free(nrcgi);
 
   CU_CP_Usage_Report_UeResourceReportItem *ue_report_item =
     (CU_CP_Usage_Report_UeResourceReportItem*)calloc(1,sizeof(CU_CP_Usage_Report_UeResourceReportItem));
@@ -558,6 +557,7 @@ void encode_kpm_ocucp_user_level(RAN_Container_t *ranco,
   ue_report_item->c_RNTI = *crnti;
   ue_report_item->serving_Cell_RF_Type = servingstr;
   ue_report_item->neighbor_Cell_RF = neighborstr;
+  if (crnti) free(crnti);
 
 
   ASN_SEQUENCE_ADD(&report_item->ueResourceReportList.list, ue_report_item);  
@@ -565,6 +565,8 @@ void encode_kpm_ocucp_user_level(RAN_Container_t *ranco,
   ranco->timestamp = *ts;
   ranco->reportContainer.present = RAN_Container__reportContainer_PR_oCU_CP_UE;
   ASN_SEQUENCE_ADD(&ranco->reportContainer.choice.oCU_CP_UE.cellResourceReportList.list, report_item);
+  if (ts->buf) free(ts->buf);
+  if (ts) free(ts);
 
   xer_fprint(stderr, &asn_DEF_RAN_Container, ranco);
   
@@ -607,6 +609,7 @@ void encode_kpm_ocucp_user_level(RAN_Container_t *ranco) {
   printf("enc3\n");
   
   report_item->nRCGI = *nrcgi;
+  if (nrcgi) free(nrcgi);
 
   CU_CP_Usage_Report_UeResourceReportItem *ue_report_item =
     (CU_CP_Usage_Report_UeResourceReportItem*)calloc(1,sizeof(CU_CP_Usage_Report_UeResourceReportItem));
@@ -692,10 +695,13 @@ void encode_kpm_odu_user_level(RAN_Container_t *ranco,
   NRCGI *nrcgi = (NRCGI*)calloc(1,sizeof(NRCGI));
   nrcgi->pLMN_Identity = *plmnidstr;
   nrcgi->nRCellIdentity = *nrcellid;
+  if (plmnidstr) free(plmnidstr);
+  if (nrcellid) free(nrcellid);
  
   printf("enc3\n"); 
   
   report_item->nRCGI = *nrcgi;
+  if (nrcgi) free(nrcgi);
 
   printf("enc3.1\n");   
 
@@ -721,6 +727,7 @@ void encode_kpm_odu_user_level(RAN_Container_t *ranco,
   
   ue_report_item->c_RNTI = *crnti;
   ue_report_item->dl_PRBUsage = &prb_usage_dl;
+  if (crnti) free(crnti);
 
   printf("enc5\n");
   
@@ -734,6 +741,7 @@ void encode_kpm_odu_user_level(RAN_Container_t *ranco,
   ranco->timestamp = *ts;
   ranco->reportContainer.present = RAN_Container__reportContainer_PR_oDU_UE;
   ASN_SEQUENCE_ADD(&ranco->reportContainer.choice.oDU_UE.cellResourceReportList.list, report_item);
+  if (ts) free(ts);
 
   xer_fprint(stderr, &asn_DEF_RAN_Container, ranco);
 
@@ -768,6 +776,7 @@ void encode_kpm_report_rancontainer_du_parameterized(E2SM_KPM_IndicationMessage_
   indicationmessage->indicationMessage.present = pres;
 
   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
+  if (format) free(format);
 
   char error_buf[300] = {0, };
   size_t errlen;
@@ -829,6 +838,7 @@ void encode_kpm_report_rancontainer_cucp_parameterized(E2SM_KPM_IndicationMessag
   indicationmessage->indicationMessage.present = pres;
 
   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
+  if (format) free(format);
 
   char error_buf[300] = {0, };
   size_t errlen;
@@ -879,6 +889,7 @@ void encode_kpm_report_rancontainer_cucp(E2SM_KPM_IndicationMessage_t* indicatio
   indicationmessage->indicationMessage.present = pres;
 
   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
+  if (format) free(format);
 
   char error_buf[300] = {0, };
   size_t errlen;
@@ -937,6 +948,7 @@ void encode_kpm_report_rancontainer_cuup_parameterized(E2SM_KPM_IndicationMessag
   indicationmessage->indicationMessage.present = pres;
 
   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
+  if (format) free(format);
 
   char error_buf[300] = {0, };
   size_t errlen;
@@ -1005,10 +1017,13 @@ void encode_kpm_report_rancontainer_cuup(E2SM_KPM_IndicationMessage_t* indicatio
   NRCGI *nrcgi = (NRCGI*)calloc(1,sizeof(NRCGI));
   nrcgi->pLMN_Identity = *plmnidstr;
   nrcgi->nRCellIdentity = *nrcellid;
+  if (plmnidstr) free(plmnidstr);
+  if (nrcellid) free(nrcellid);
  
   printf("enc3\n"); 
   
   report_item->nRCGI = *nrcgi;
+  if (nrcgi) free(nrcgi);
 
   CU_CP_Usage_Report_UeResourceReportItem *ue_report_item =
     (CU_CP_Usage_Report_UeResourceReportItem*)calloc(1,sizeof(CU_CP_Usage_Report_UeResourceReportItem));
@@ -1067,6 +1082,7 @@ void encode_kpm_report_rancontainer_cuup(E2SM_KPM_IndicationMessage_t* indicatio
   indicationmessage->indicationMessage.present = pres;
 
   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
+  if (format) free(format);
 
   char error_buf[300] = {0, };
   size_t errlen;
@@ -1118,20 +1134,11 @@ void encode_kpm_report_style1_parameterized(E2SM_KPM_IndicationMessage_t* indica
   fqi_item->ul_PRBUsage = &ul_prb_usage;
 
   uint8_t *buf1 = (uint8_t*)"4";  
-  OCTET_STRING_t *sst = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
-  sst->size = 6;
-  sst->buf = (uint8_t*)calloc(1,6);
-  memcpy(sst->buf,buf1,sst->size);
 
   //  std::string sd = "SD1";
   //  std::vector<uint8_t> sdvec(sd.begin(), sd.end());
   //  uint8_t *bufz = &sdvec[0];
   uint8_t *bufz = (uint8_t*)"SD1";
-  OCTET_STRING_t *sds = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
-  sds->size = 3;
-  sds->buf = (uint8_t*)calloc(1,3);
-  memcpy(sds->buf, bufz, sds->size);
-
   
   SNSSAI_t *snssai = (SNSSAI_t*)calloc(1, sizeof(SNSSAI_t));
   ASN_STRUCT_RESET(asn_DEF_SNSSAI,snssai);
@@ -1148,6 +1155,7 @@ void encode_kpm_report_style1_parameterized(E2SM_KPM_IndicationMessage_t* indica
     (SlicePerPlmnPerCellListItem_t*)calloc(1,sizeof(SlicePerPlmnPerCellListItem_t));
   sliceitem->sliceID = *snssai;
   ASN_SEQUENCE_ADD(&sliceitem->fQIPERSlicesPerPlmnPerCellList.list, fqi_item);
+  if (snssai) free(snssai);
 
   uint8_t *buf2 = (uint8_t*)"747";
   
@@ -1161,6 +1169,7 @@ void encode_kpm_report_style1_parameterized(E2SM_KPM_IndicationMessage_t* indica
   percellitem1->pLMN_Identity = *plmnid;
   percellitem1->du_PM_5GC = (FGC_DU_PM_Container*)calloc(1,sizeof(FGC_DU_PM_Container));
   ASN_SEQUENCE_ADD(&percellitem1->du_PM_5GC->slicePerPlmnPerCellList.list, sliceitem);
+  if (plmnid) free(plmnid);
 
   OCTET_STRING_t *plmnidstr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
   plmnidstr->buf = (uint8_t*)calloc(3,1);
@@ -1179,6 +1188,8 @@ void encode_kpm_report_style1_parameterized(E2SM_KPM_IndicationMessage_t* indica
   NRCGI *nrcgi = (NRCGI*)calloc(1,sizeof(NRCGI));
   nrcgi->pLMN_Identity = *plmnidstr;
   nrcgi->nRCellIdentity = *nrcellid;
+  if (plmnidstr) free(plmnidstr);
+  if (nrcellid) free(nrcellid);
     
 
   CellResourceReportListItem_t *listitem1 = (CellResourceReportListItem_t*)calloc(1,sizeof(CellResourceReportListItem_t));
@@ -1186,6 +1197,7 @@ void encode_kpm_report_style1_parameterized(E2SM_KPM_IndicationMessage_t* indica
   listitem1->dl_TotalofAvailablePRBs = dl_prbs;
   listitem1->ul_TotalofAvailablePRBs = ul_prbs;
   ASN_SEQUENCE_ADD(&listitem1->servedPlmnPerCellList.list, percellitem1);
+  if (nrcgi) free(nrcgi);
   
 
   ODU_PF_Container_t *ducont = (ODU_PF_Container_t*)calloc(1,sizeof(ODU_PF_Container_t));
@@ -1198,6 +1210,7 @@ void encode_kpm_report_style1_parameterized(E2SM_KPM_IndicationMessage_t* indica
   ASN_STRUCT_RESET(asn_DEF_PF_Container, pfcontainer);
   pfcontainer->present = pres1;
   pfcontainer->choice.oDU = *ducont;
+  if (ducont) free(ducont);
 
   PM_Containers_List_t *containers_list = (PM_Containers_List_t*)calloc(1, sizeof(PM_Containers_List_t));
   ASN_STRUCT_RESET(asn_DEF_PM_Containers_List, containers_list);
@@ -1214,6 +1227,7 @@ void encode_kpm_report_style1_parameterized(E2SM_KPM_IndicationMessage_t* indica
   indicationmessage->indicationMessage.present = pres;
 
   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
+  if (format) free(format);
 
   char error_buf[300] = {0, };
   size_t errlen;
@@ -1259,20 +1273,10 @@ void encode_kpm_report_style1(E2SM_KPM_IndicationMessage_t* indicationmessage) {
   fqi_item->ul_PRBUsage = &ul_prb_usage;
 
   uint8_t *buf1 = (uint8_t*)"4";  
-  OCTET_STRING_t *sst = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
-  sst->size = 6;
-  sst->buf = (uint8_t*)calloc(1,6);
-  memcpy(sst->buf,buf1,sst->size);
-
   //  std::string sd = "SD1";
   //  std::vector<uint8_t> sdvec(sd.begin(), sd.end());
   //  uint8_t *bufz = &sdvec[0];
   uint8_t *bufz = (uint8_t*)"SD1";
-  OCTET_STRING_t *sds = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
-  sds->size = 3;
-  sds->buf = (uint8_t*)calloc(1,3);
-  memcpy(sds->buf, bufz, sds->size);
-
   
   SNSSAI_t *snssai = (SNSSAI_t*)calloc(1, sizeof(SNSSAI_t));
   ASN_STRUCT_RESET(asn_DEF_SNSSAI,snssai);
@@ -1289,6 +1293,7 @@ void encode_kpm_report_style1(E2SM_KPM_IndicationMessage_t* indicationmessage) {
     (SlicePerPlmnPerCellListItem_t*)calloc(1,sizeof(SlicePerPlmnPerCellListItem_t));
   sliceitem->sliceID = *snssai;
   ASN_SEQUENCE_ADD(&sliceitem->fQIPERSlicesPerPlmnPerCellList.list, fqi_item);
+  if (snssai) free(snssai);
 
   uint8_t *buf2 = (uint8_t*)"747";
   
@@ -1320,6 +1325,8 @@ void encode_kpm_report_style1(E2SM_KPM_IndicationMessage_t* indicationmessage) {
   NRCGI *nrcgi = (NRCGI*)calloc(1,sizeof(NRCGI));
   nrcgi->pLMN_Identity = *plmnidstr;
   nrcgi->nRCellIdentity = *nrcellid;
+  if (plmnidstr) free(plmnidstr);
+  if (nrcellid) free(nrcellid);
     
   long dl_prbs = (long)100;
   long ul_prbs = (long)120;
@@ -1329,6 +1336,7 @@ void encode_kpm_report_style1(E2SM_KPM_IndicationMessage_t* indicationmessage) {
   listitem1->dl_TotalofAvailablePRBs = &dl_prbs;
   listitem1->ul_TotalofAvailablePRBs = &ul_prbs;
   ASN_SEQUENCE_ADD(&listitem1->servedPlmnPerCellList.list, percellitem1);
+  if (nrcgi) free(nrcgi);
   
 
   ODU_PF_Container_t *ducont = (ODU_PF_Container_t*)calloc(1,sizeof(ODU_PF_Container_t));
@@ -1341,6 +1349,7 @@ void encode_kpm_report_style1(E2SM_KPM_IndicationMessage_t* indicationmessage) {
   ASN_STRUCT_RESET(asn_DEF_PF_Container, pfcontainer);
   pfcontainer->present = pres1;
   pfcontainer->choice.oDU = *ducont;
+  if (ducont) free(ducont);
 
   PM_Containers_List_t *containers_list = (PM_Containers_List_t*)calloc(1, sizeof(PM_Containers_List_t));
   ASN_STRUCT_RESET(asn_DEF_PM_Containers_List, containers_list);
@@ -1357,6 +1366,7 @@ void encode_kpm_report_style1(E2SM_KPM_IndicationMessage_t* indicationmessage) {
   indicationmessage->indicationMessage.present = pres;
 
   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
+  if (format) free(format);
 
   char error_buf[300] = {0, };
   size_t errlen;
@@ -1509,18 +1519,7 @@ void encode_kpm_report_style5_parameterized(E2SM_KPM_IndicationMessage_t* indica
 
 
   uint8_t *buf1 = (uint8_t*)"4";  
-  OCTET_STRING_t *sst = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
-  sst->size = 6;
-  sst->buf = (uint8_t*)calloc(1,6);
-  memcpy(sst->buf,sst_buf,sst->size);
-
-
   uint8_t *bufz = (uint8_t*)"SD1";
-  OCTET_STRING_t *sds = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
-  sds->size = 3;
-  sds->buf = (uint8_t*)calloc(1,3);
-  memcpy(sds->buf, sd_buf, sds->size);
-
   
   SNSSAI_t *snssai = (SNSSAI_t*)calloc(1, sizeof(SNSSAI_t));
   ASN_STRUCT_RESET(asn_DEF_SNSSAI,snssai);
@@ -1538,6 +1537,7 @@ void encode_kpm_report_style5_parameterized(E2SM_KPM_IndicationMessage_t* indica
   ASN_STRUCT_RESET(asn_DEF_SliceToReportListItem, slicelistitem);
   slicelistitem->sliceID = *snssai;
   int ret = ASN_SEQUENCE_ADD(&slicelistitem->fQIPERSlicesPerPlmnList.list, fqilistitem);
+  if (snssai) free(snssai);
 
   asn_codec_ctx_t *opt_cod;  
 
@@ -1576,6 +1576,7 @@ void encode_kpm_report_style5_parameterized(E2SM_KPM_IndicationMessage_t* indica
   ASN_STRUCT_RESET(asn_DEF_PlmnID_List, plmnidlist);
   plmnidlist->pLMN_Identity = *plmnid;
   plmnidlist->cu_UP_PM_5GC = pm_format;
+  if (plmnid) free(plmnid);
 
   CUUPMeasurement_Container_t *meas_cont = (CUUPMeasurement_Container_t*)calloc(1, sizeof(CUUPMeasurement_Container_t));
   ASN_STRUCT_RESET(asn_DEF_CUUPMeasurement_Container, meas_cont);
@@ -1588,6 +1589,7 @@ void encode_kpm_report_style5_parameterized(E2SM_KPM_IndicationMessage_t* indica
   ASN_STRUCT_RESET(asn_DEF_PF_ContainerListItem, listitem1);
   listitem1->interface_type = 2;
   listitem1->o_CU_UP_PM_Container = *meas_cont;
+  if (meas_cont) free(meas_cont);
 
   OCUUP_PF_Container_t *cuupcont = (OCUUP_PF_Container_t*)calloc(1,sizeof(OCUUP_PF_Container_t));
   ASN_STRUCT_RESET(asn_DEF_OCUUP_PF_Container, cuupcont);
@@ -1600,6 +1602,7 @@ void encode_kpm_report_style5_parameterized(E2SM_KPM_IndicationMessage_t* indica
   ASN_STRUCT_RESET(asn_DEF_PF_Container, pfcontainer);
   pfcontainer->present = pres1;
   pfcontainer->choice.oCU_UP = *cuupcont;
+  if (cuupcont) free(cuupcont);
 
   PM_Containers_List_t *containers_list = (PM_Containers_List_t*)calloc(1, sizeof(PM_Containers_List_t));
   ASN_STRUCT_RESET(asn_DEF_PM_Containers_List, containers_list);
@@ -1616,6 +1619,7 @@ void encode_kpm_report_style5_parameterized(E2SM_KPM_IndicationMessage_t* indica
   indicationmessage->indicationMessage.present = pres;
 
   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
+  if (format) free(format);
 
   char error_buf[300] = {0, };
   size_t errlen;
@@ -1679,18 +1683,7 @@ void encode_kpm_report_style5(E2SM_KPM_IndicationMessage_t* indicationmessage) {
 
 
   uint8_t *buf1 = (uint8_t*)"4";  
-  OCTET_STRING_t *sst = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
-  sst->size = 6;
-  sst->buf = (uint8_t*)calloc(1,6);
-  memcpy(sst->buf,buf1,sst->size);
-
-
   uint8_t *bufz = (uint8_t*)"SD1";
-  OCTET_STRING_t *sds = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
-  sds->size = 3;
-  sds->buf = (uint8_t*)calloc(1,3);
-  memcpy(sds->buf, bufz, sds->size);
-
   
   SNSSAI_t *snssai = (SNSSAI_t*)calloc(1, sizeof(SNSSAI_t));
   ASN_STRUCT_RESET(asn_DEF_SNSSAI,snssai);
@@ -1708,6 +1701,7 @@ void encode_kpm_report_style5(E2SM_KPM_IndicationMessage_t* indicationmessage) {
   ASN_STRUCT_RESET(asn_DEF_SliceToReportListItem, slicelistitem);
   slicelistitem->sliceID = *snssai;
   int ret = ASN_SEQUENCE_ADD(&slicelistitem->fQIPERSlicesPerPlmnList.list, fqilistitem);
+  if (snssai) free(snssai);
 
   asn_codec_ctx_t *opt_cod;  
 
@@ -1758,6 +1752,7 @@ void encode_kpm_report_style5(E2SM_KPM_IndicationMessage_t* indicationmessage) {
   ASN_STRUCT_RESET(asn_DEF_PF_ContainerListItem, listitem1);
   listitem1->interface_type = 2;
   listitem1->o_CU_UP_PM_Container = *meas_cont;
+  if (meas_cont) free(meas_cont);
 
   OCUUP_PF_Container_t *cuupcont = (OCUUP_PF_Container_t*)calloc(1,sizeof(OCUUP_PF_Container_t));
   ASN_STRUCT_RESET(asn_DEF_OCUUP_PF_Container, cuupcont);
@@ -1770,6 +1765,7 @@ void encode_kpm_report_style5(E2SM_KPM_IndicationMessage_t* indicationmessage) {
   ASN_STRUCT_RESET(asn_DEF_PF_Container, pfcontainer);
   pfcontainer->present = pres1;
   pfcontainer->choice.oCU_UP = *cuupcont;
+  if (cuupcont) free(cuupcont);
 
   PM_Containers_List_t *containers_list = (PM_Containers_List_t*)calloc(1, sizeof(PM_Containers_List_t));
   ASN_STRUCT_RESET(asn_DEF_PM_Containers_List, containers_list);
@@ -1786,6 +1782,7 @@ void encode_kpm_report_style5(E2SM_KPM_IndicationMessage_t* indicationmessage) {
   indicationmessage->indicationMessage.present = pres;
 
   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
+  if (format) free(format);
 
   char error_buf[300] = {0, };
   size_t errlen;
index 0370984..bcfb513 100755 (executable)
@@ -369,6 +369,7 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long
                                                                   ATS_ALIGNED_BASIC_PER,
                                                                   &asn_DEF_E2SM_KPM_IndicationMessage,
                                                                   ind_msg_cucp_ue, e2sm_message_buf_cucp_ue, e2sm_message_buf_size_cucp_ue);
+         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, ind_msg_cucp_ue);
          
          fprintf(stderr, "er encded is %d\n", er_message_cucp_ue.encoded);
          fprintf(stderr, "after encoding message\n");
@@ -386,6 +387,7 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long
                                                                  ATS_ALIGNED_BASIC_PER,
                                                                  &asn_DEF_E2SM_KPM_IndicationHeader,
                                                                  ind_header_cucp_ue, e2sm_header_buf_cucp_ue, e2sm_header_buf_size_cucp_ue);
+         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, ind_header_cucp_ue);
 
          fprintf(stderr, "er encded is %d\n", er_header_cucp_ue.encoded);
          fprintf(stderr, "error buf is %s\n", (char*)e2sm_header_buf_cucp_ue);
@@ -427,6 +429,7 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long
                                                               ATS_ALIGNED_BASIC_PER,
                                                               &asn_DEF_E2SM_KPM_IndicationMessage,
                                                               ind_msg_cuup_ue, e2sm_message_buf_cuup_ue, e2sm_message_buf_size_cuup_ue);
+         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, ind_msg_cuup_ue);
          
          fprintf(stderr, "er encded is %d\n", er_message_cuup_ue.encoded);
          fprintf(stderr, "after encoding message\n");
@@ -442,6 +445,7 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long
                                                                  ATS_ALIGNED_BASIC_PER,
                                                                  &asn_DEF_E2SM_KPM_IndicationHeader,
                                                                  ind_header_cuup_ue, e2sm_header_buf_cuup_ue, e2sm_header_buf_size_cuup_ue);
+         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, ind_header_cuup_ue);
          
          
          E2AP_PDU *pdu_cuup_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));        
@@ -480,6 +484,7 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long
                                                                 ind_message_du_ue,
                                                                 e2sm_message_buf_du_ue,
                                                                 e2sm_message_buf_size_du_ue);
+         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, ind_message_du_ue);
          
          fprintf(stderr, "er encded is %d\n", er_message_du_ue.encoded);
          fprintf(stderr, "after encoding message\n");
@@ -496,6 +501,7 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long
                                                                &asn_DEF_E2SM_KPM_IndicationHeader,
                                                                ind_header_du_ue, e2sm_header_buf_du_ue,
                                                                e2sm_header_buf_size_du_ue);
+         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, ind_header_du_ue);
          
          
          E2AP_PDU *pdu_du_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
@@ -597,6 +603,7 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long
                                                                  ATS_ALIGNED_BASIC_PER,
                                                                  &asn_DEF_E2SM_KPM_IndicationMessage,
                                                                  ind_msg_style5, e2sm_message_buf_style5, e2sm_message_buf_size_style5);
+         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, ind_msg_style5);
          
          fprintf(stderr, "er encded is %d\n", er_message_style5.encoded);
          fprintf(stderr, "after encoding message\n");
@@ -616,6 +623,7 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long
                                                                 &asn_DEF_E2SM_KPM_IndicationHeader,
                                                                 ind_header_style5,
                                                                 e2sm_header_buf_style5, e2sm_header_buf_size_style5);    
+         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, ind_header_style5);
          
          
          encoding::generate_e2apv1_indication_request_parameterized(pdu_style5, requestorId,
@@ -660,6 +668,7 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long
                                                                  &asn_DEF_E2SM_KPM_IndicationMessage,
                                                                  ind_message_style1,
                                                                  e2sm_message_buf_style1, e2sm_message_buf_size_style1);
+         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, ind_message_style1);
          
          fprintf(stderr, "er encded is %d\n", er_message_style1.encoded);
          fprintf(stderr, "after encoding message\n");
@@ -681,6 +690,7 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long
                                                                 &asn_DEF_E2SM_KPM_IndicationHeader,
                                                                 ind_header_style1,
                                                                 e2sm_header_buf_style1, e2sm_header_buf_size_style1);
+         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, ind_header_style1);
          
          encoding::generate_e2apv1_indication_request_parameterized(pdu_style1, requestorId,
                                                                     instanceId, ranFunctionId,
index 852cbdd..e28cbd4 100755 (executable)
@@ -76,6 +76,7 @@ void E2Sim::encode_and_send_sctp_data(E2AP_PDU_t* pdu)
 
   data.len = e2ap_asn1c_encode_pdu(pdu, &buf);
   memcpy(data.buffer, buf, min(data.len, MAX_SCTP_BUFFER));
+  if (buf) free(buf);
 
   sctp_send_data(client_fd, data);
 }
index 1416e5e..a6bf517 100755 (executable)
@@ -60,9 +60,7 @@ long encoding::get_function_id_from_subscription(E2AP_PDU_t *e2ap_pdu) {
 
   RICsubscriptionRequest_t orig_req =
     e2ap_pdu->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
-  RICsubscriptionResponse_IEs_t *ricreqid =
-    (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
-                                          
+
   int count = orig_req.protocolIEs.list.count;
   int size = orig_req.protocolIEs.list.size;
   
@@ -180,13 +178,17 @@ void encoding::generate_e2apv1_setup_request_parameterized(E2AP_PDU_t *e2ap_pdu,
   GNB_ID_Choice_PR pres2 = GNB_ID_Choice_PR_gnb_ID;
   gnbchoice->present = pres2;
   gnbchoice->choice.gnb_ID = *gnb_bstring;
+  if (gnb_bstring) free(gnb_bstring);
 
   GlobalgNB_ID_t *gnb = (GlobalgNB_ID_t*)calloc(1, sizeof(GlobalgNB_ID_t));
   gnb->plmn_id = *plmn;
   gnb->gnb_id = *gnbchoice;
+  if (plmn) free(plmn);
+  if (gnbchoice) free(gnbchoice);
 
   GlobalE2node_gNB_ID_t *e2gnb = (GlobalE2node_gNB_ID_t*)calloc(1, sizeof(GlobalE2node_gNB_ID_t));
   e2gnb->global_gNB_ID = *gnb;
+  if (gnb) free(gnb);
 
   GlobalE2node_ID_t *globale2nodeid = (GlobalE2node_ID_t*)calloc(1, sizeof(GlobalE2node_ID_t));
   GlobalE2node_ID_PR pres;
@@ -201,6 +203,7 @@ void encoding::generate_e2apv1_setup_request_parameterized(E2AP_PDU_t *e2ap_pdu,
   e2setuprid->criticality = 0;
   e2setuprid->value.choice.GlobalE2node_ID = *globale2nodeid;
   e2setuprid->value.present = pres3;
+  if(globale2nodeid) free(globale2nodeid);
 
 
   auto *ranFlistIEs = (E2setupRequestIEs_t *)calloc(1, sizeof(E2setupRequestIEs_t));
@@ -244,6 +247,7 @@ void encoding::generate_e2apv1_setup_request_parameterized(E2AP_PDU_t *e2ap_pdu,
   initmsg->criticality = Criticality_reject;
   initmsg->value.present = pres4;
   initmsg->value.choice.E2setupRequest = *e2setupreq;
+  if (e2setupreq) free(e2setupreq);
 
   E2AP_PDU_PR pres5;
   pres5 = E2AP_PDU_PR_initiatingMessage;
@@ -450,6 +454,7 @@ void encoding::generate_e2apv1_subscription_response_success(E2AP_PDU *e2ap_pdu,
   RICaction_Admitted_List_t* admlist = 
     (RICaction_Admitted_List_t*)calloc(1,sizeof(RICaction_Admitted_List_t));
   ricactionadmitted->value.choice.RICaction_Admitted_List = *admlist;
+  if (admlist) free(admlist);
 
 
   int numAccept = accept_size;
@@ -514,6 +519,7 @@ void encoding::generate_e2apv1_subscription_response_success(E2AP_PDU *e2ap_pdu,
   successoutcome->criticality = 0;
   successoutcome->value.present = pres2;
   successoutcome->value.choice.RICsubscriptionResponse = *ricsubresp;
+  if (ricsubresp) free(ricsubresp);
 
   E2AP_PDU_PR pres5 = E2AP_PDU_PR_successfulOutcome;
   
@@ -745,14 +751,6 @@ void encoding::generate_e2apv1_indication_request_parameterized(E2AP_PDU *e2ap_p
   ricind_ies5->value.present = pres3;
   ricind_ies5->value.choice.RICindicationType = 0;
 
-
-  uint8_t *buf2 = (uint8_t *)"reportheader";
-  OCTET_STRING_t *hdr_str = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
-
-  hdr_str->buf = (uint8_t*)calloc(1,header_length);
-  hdr_str->size = header_length;
-  memcpy(hdr_str->buf, ind_header_buf, header_length);
-
   fprintf(stderr, "ind3\n");
 
   ricind_ies6->value.choice.RICindicationHeader.buf = (uint8_t*)calloc(1,header_length);
@@ -844,6 +842,7 @@ void encoding::generate_e2apv1_indication_request_parameterized(E2AP_PDU *e2ap_p
   initmsg->criticality = 1;
   initmsg->value.present = pres4;
   initmsg->value.choice.RICindication = *ricindication;
+  if (ricindication) free(ricindication);
 
   E2AP_PDU_PR pres5;
   pres5 = E2AP_PDU_PR_initiatingMessage;
index 81aa780..ae72048 100755 (executable)
@@ -213,6 +213,7 @@ void e2ap_handle_sctp_data(int &socket_fd, sctp_buffer_t &data, bool xmlenc, E2S
 \r
       break;\r
     }\r
+  ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);\r
 }\r
 \r
 void e2ap_handle_E2SeviceRequest(E2AP_PDU_t* pdu, int &socket_fd, E2Sim *e2sim) {\r