Fix double free corruption form ASN_STRUCT_FREE
[sim/e2-interface.git] / e2sim / e2sm_examples / kpm_e2sm / src / kpm / encode_kpm.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 613e793..55abcb5
@@ -33,18 +33,14 @@ void encode_kpm_function_description(E2SM_KPM_RANfunction_Description_t* ranfunc
   uint8_t *buf = (uint8_t*)"ORAN-E2SM-KPM";
   uint8_t *buf2 = (uint8_t*)"KPM monitor";
   uint8_t *buf3 = (uint8_t*)"OID123";
-
-  OCTET_STRING_t *sname = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
-  sname->buf = (uint8_t*)calloc(1,13);
-  
-  memcpy(sname->buf, buf, 13);
-  sname->size = strlen((char*)buf);
-  ranfunc_desc->ranFunction_Name.ranFunction_ShortName = *sname;
-
   long inst = 1;
 
   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_RANfunction_Description, ranfunc_desc);
 
+  ranfunc_desc->ranFunction_Name.ranFunction_ShortName.size = strlen((char*)buf);
+  ranfunc_desc->ranFunction_Name.ranFunction_ShortName.buf = (uint8_t*)calloc(strlen((char*)buf), sizeof(uint8_t));
+  memcpy(ranfunc_desc->ranFunction_Name.ranFunction_ShortName.buf, buf, ranfunc_desc->ranFunction_Name.ranFunction_ShortName.size);
+
   //  ranfunc_desc->ranFunction_Name.ranFunction_Description = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
   ranfunc_desc->ranFunction_Name.ranFunction_Description.buf = (uint8_t*)calloc(1,strlen((char*)buf2));
   memcpy(ranfunc_desc->ranFunction_Name.ranFunction_Description.buf, buf2, strlen((char*)buf2));
@@ -187,26 +183,9 @@ void encode_e2sm_kpm_indication_header(E2SM_KPM_IndicationHeader_t *ihead, uint8
   E2SM_KPM_IndicationHeader_Format1_t* ind_header =
     (E2SM_KPM_IndicationHeader_Format1_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_Format1_t));
   
-  OCTET_STRING_t *plmnid = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
-  plmnid->buf = (uint8_t*)calloc(3,1);
-  plmnid->size = 3;
-  memcpy(plmnid->buf, plmnid_buf, plmnid->size);
-  
   //  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);
@@ -230,18 +209,6 @@ void encode_e2sm_kpm_indication_header(E2SM_KPM_IndicationHeader_t *ihead, uint8
   */  
   nrcellid->bits_unused = 4;
   
-  BIT_STRING_t *gnb_bstring = (BIT_STRING_t*)calloc(1, sizeof(BIT_STRING_t));;
-  gnb_bstring->buf = (uint8_t*)calloc(1,4);
-  gnb_bstring->size = 4;
-  memcpy(gnb_bstring->buf, gnbid_buf, 4);
-  /*
-  gnb_bstring->buf[0] = 0xB5;
-  gnb_bstring->buf[1] = 0xC6;
-  gnb_bstring->buf[2] = 0x77;
-  gnb_bstring->buf[3] = 0x88;
-  */
-  
-  gnb_bstring->bits_unused = gnbid_unused;
   
   INTEGER_t *cuup_id = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
   //  uint8_t buffer[1];
@@ -264,20 +231,44 @@ void encode_e2sm_kpm_indication_header(E2SM_KPM_IndicationHeader_t *ihead, uint8
   cuupname->buf = (uint8_t*)calloc(1,8);
   memcpy(cuupname->buf, cuupname_buf, cuupname->size);
 
+  OCTET_STRING_t *plmnid_id_GlobalKPMnode_ID = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
+  plmnid_id_GlobalKPMnode_ID->size = strlen((char *)plmnid_buf);
+  plmnid_id_GlobalKPMnode_ID->buf = (uint8_t*)calloc(plmnid_id_GlobalKPMnode_ID->size, sizeof(uint8_t));
+  memcpy(plmnid_id_GlobalKPMnode_ID->buf, plmnid_buf, plmnid_id_GlobalKPMnode_ID->size);
+
+  BIT_STRING_t *gnb_bstring_id_GlobalKPMnode_ID = (BIT_STRING_t*)calloc(1, sizeof(BIT_STRING_t));
+  gnb_bstring_id_GlobalKPMnode_ID->size = strlen((char *)gnbid_buf);
+  gnb_bstring_id_GlobalKPMnode_ID->buf = (uint8_t*)calloc(gnb_bstring_id_GlobalKPMnode_ID->size, sizeof(uint8_t));
+  memcpy(gnb_bstring_id_GlobalKPMnode_ID->buf, gnbid_buf, gnb_bstring_id_GlobalKPMnode_ID->size);
+  gnb_bstring_id_GlobalKPMnode_ID->bits_unused = gnbid_unused;
 
   ind_header->id_GlobalKPMnode_ID = (GlobalKPMnode_ID*)calloc(1,sizeof(GlobalKPMnode_ID));
   ind_header->id_GlobalKPMnode_ID->present = GlobalKPMnode_ID_PR_gNB;
   ind_header->id_GlobalKPMnode_ID->choice.gNB.global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
-  ind_header->id_GlobalKPMnode_ID->choice.gNB.global_gNB_ID.gnb_id.choice.gnb_ID = *gnb_bstring;
-  ind_header->id_GlobalKPMnode_ID->choice.gNB.global_gNB_ID.plmn_id = *plmnid;
+  ind_header->id_GlobalKPMnode_ID->choice.gNB.global_gNB_ID.gnb_id.choice.gnb_ID = *gnb_bstring_id_GlobalKPMnode_ID;
+  ind_header->id_GlobalKPMnode_ID->choice.gNB.global_gNB_ID.plmn_id = *plmnid_id_GlobalKPMnode_ID;
   ind_header->id_GlobalKPMnode_ID->choice.gNB.gNB_CU_UP_ID = cuup_id;
+  if (plmnid_id_GlobalKPMnode_ID) free(plmnid_id_GlobalKPMnode_ID);
+  if (gnb_bstring_id_GlobalKPMnode_ID) free(gnb_bstring_id_GlobalKPMnode_ID);
 
 
-  
+  OCTET_STRING_t *plmnid_nRCGI = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
+  plmnid_nRCGI->buf = (uint8_t*)calloc(3,1);
+  plmnid_nRCGI->size = 3;
+  memcpy(plmnid_nRCGI->buf, plmnid_buf, plmnid_nRCGI->size);
+
   ind_header->nRCGI = (NRCGI*)calloc(1,sizeof(NRCGI));
-  ind_header->nRCGI->pLMN_Identity = *plmnid;
+  ind_header->nRCGI->pLMN_Identity = *plmnid_nRCGI;
   ind_header->nRCGI->nRCellIdentity = *nrcellid;
-  
+  if (plmnid_nRCGI) free(plmnid_nRCGI);
+  if (nrcellid) free(nrcellid);
+
+
+  OCTET_STRING_t *plmnid = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
+  plmnid->buf = (uint8_t*)calloc(3,1);
+  plmnid->size = 3;
+  memcpy(plmnid->buf, plmnid_buf, plmnid->size);
+
   ind_header->pLMN_Identity = plmnid;
   //  memcpy(ind_header->fiveQI, &fqival, 4);
   
@@ -288,12 +279,26 @@ 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);
+
+
+  OCTET_STRING_t *plmnid_global_GNB_ID = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
+  plmnid_global_GNB_ID->buf = (uint8_t*)calloc(3,1);
+  plmnid_global_GNB_ID->size = 3;
+  memcpy(plmnid_global_GNB_ID->buf, plmnid_buf, plmnid_global_GNB_ID->size);
+
+  BIT_STRING_t *gnb_bstring_global_GNB_ID = (BIT_STRING_t*)calloc(1, sizeof(BIT_STRING_t));;
+  gnb_bstring_global_GNB_ID->buf = (uint8_t*)calloc(1,4);
+  gnb_bstring_global_GNB_ID->size = 4;
+  memcpy(gnb_bstring_global_GNB_ID->buf, gnbid_buf, 4);
+  gnb_bstring_global_GNB_ID->bits_unused = gnbid_unused;
 
   ind_header->global_GNB_ID = (GlobalgNB_ID*)calloc(1,sizeof(GlobalgNB_ID));
-  ind_header->global_GNB_ID->plmn_id = *plmnid;
+  ind_header->global_GNB_ID->plmn_id = *plmnid_global_GNB_ID;
   ind_header->global_GNB_ID->gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
-  ind_header->global_GNB_ID->gnb_id.choice.gnb_ID = *gnb_bstring;
+  ind_header->global_GNB_ID->gnb_id.choice.gnb_ID = *gnb_bstring_global_GNB_ID;
+  if (plmnid_global_GNB_ID) free(plmnid_global_GNB_ID);
+  if (gnb_bstring_global_GNB_ID) free(gnb_bstring_global_GNB_ID);
 
 
   //  long msg_type = 2;
@@ -303,6 +308,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 +353,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 +476,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 +484,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 +527,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 +572,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 +580,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 +624,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 +710,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");   
 
@@ -718,13 +739,18 @@ void encode_kpm_odu_user_level(RAN_Container_t *ranco,
 
   printf("enc4\n");  
 
+  long *p_prb_usage_dl = (long*)calloc(1, sizeof(long));
+  long *p_prb_usage_ul = (long*)calloc(1, sizeof(long));
+  *p_prb_usage_dl = (long)prb_usage_dl;
+  *p_prb_usage_ul = (long)prb_usage_ul;
   
   ue_report_item->c_RNTI = *crnti;
-  ue_report_item->dl_PRBUsage = &prb_usage_dl;
+  ue_report_item->dl_PRBUsage = p_prb_usage_dl;
+  if (crnti) free(crnti);
 
   printf("enc5\n");
   
-  ue_report_item->ul_PRBUsage = &prb_usage_ul;
+  ue_report_item->ul_PRBUsage = p_prb_usage_ul;
 
   printf("enc6\n");
   
@@ -734,6 +760,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,9 +795,10 @@ 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 = (char*)calloc(300, sizeof(char));
-  size_t errlen;
+  char error_buf[300] = {0, };
+  size_t errlen = 0;
 
   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
   printf("error length %d\n", errlen);
@@ -780,10 +808,10 @@ void encode_kpm_report_rancontainer_du_parameterized(E2SM_KPM_IndicationMessage_
 
   asn_codec_ctx_t *opt_cod;
 
-  uint8_t e2smbuffer[8192];
+  uint8_t e2smbuffer[8192] = {0, };
   size_t e2smbuffer_size = 8192;
 
-  uint8_t e2smbuffer2[8192];
+  uint8_t e2smbuffer2[8192] = {0, };
   size_t e2smbuffer_size2 = 8192;
 
   asn_enc_rval_t er =
@@ -829,9 +857,10 @@ 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 = (char*)calloc(300, sizeof(char));
-  size_t errlen;
+  char error_buf[300] = {0, };
+  size_t errlen = 0;
 
   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
   printf("error length %d\n", errlen);
@@ -841,10 +870,10 @@ void encode_kpm_report_rancontainer_cucp_parameterized(E2SM_KPM_IndicationMessag
 
   asn_codec_ctx_t *opt_cod;
 
-  uint8_t e2smbuffer[8192];
+  uint8_t e2smbuffer[8192] = {0, };
   size_t e2smbuffer_size = 8192;
 
-  uint8_t e2smbuffer2[8192];
+  uint8_t e2smbuffer2[8192] = {0, };
   size_t e2smbuffer_size2 = 8192;
 
   asn_enc_rval_t er =
@@ -879,9 +908,10 @@ 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 = (char*)calloc(300, sizeof(char));
-  size_t errlen;
+  char error_buf[300] = {0, };
+  size_t errlen = 0;
 
   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
   printf("error length %d\n", errlen);
@@ -891,10 +921,10 @@ void encode_kpm_report_rancontainer_cucp(E2SM_KPM_IndicationMessage_t* indicatio
 
   asn_codec_ctx_t *opt_cod;
 
-  uint8_t e2smbuffer[8192];
+  uint8_t e2smbuffer[8192] = {0, };
   size_t e2smbuffer_size = 8192;
 
-  uint8_t e2smbuffer2[8192];
+  uint8_t e2smbuffer2[8192] = {0, };
   size_t e2smbuffer_size2 = 8192;
 
   asn_enc_rval_t er =
@@ -937,9 +967,10 @@ 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 = (char*)calloc(300, sizeof(char));
-  size_t errlen;
+  char error_buf[300] = {0, };
+  size_t errlen = 0;
 
   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
   printf("error length %d\n", errlen);
@@ -949,10 +980,10 @@ void encode_kpm_report_rancontainer_cuup_parameterized(E2SM_KPM_IndicationMessag
 
   asn_codec_ctx_t *opt_cod;
 
-  uint8_t e2smbuffer[8192];
+  uint8_t e2smbuffer[8192] = {0, };
   size_t e2smbuffer_size = 8192;
 
-  uint8_t e2smbuffer2[8192];
+  uint8_t e2smbuffer2[8192] = {0, };
   size_t e2smbuffer_size2 = 8192;
 
   //  xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);  
@@ -1005,10 +1036,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,9 +1101,10 @@ 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 = (char*)calloc(300, sizeof(char));
-  size_t errlen;
+  char error_buf[300] = {0, };
+  size_t errlen = 0;
 
   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
   printf("error length %d\n", errlen);
@@ -1079,10 +1114,10 @@ void encode_kpm_report_rancontainer_cuup(E2SM_KPM_IndicationMessage_t* indicatio
 
   asn_codec_ctx_t *opt_cod;
 
-  uint8_t e2smbuffer[8192];
+  uint8_t e2smbuffer[8192] = {0, };
   size_t e2smbuffer_size = 8192;
 
-  uint8_t e2smbuffer2[8192];
+  uint8_t e2smbuffer2[8192] = {0, };
   size_t e2smbuffer_size2 = 8192;
 
   asn_enc_rval_t er =
@@ -1101,8 +1136,8 @@ void encode_kpm_report_style1_parameterized(E2SM_KPM_IndicationMessage_t* indica
                                            long fiveqi,
                                            long dl_prb_usage,
                                            long ul_prb_usage,
-                                           uint8_t* sd_buf,
                                            uint8_t* sst_buf,
+                                           uint8_t* sd_buf,
                                            uint8_t* plmnid_buf,
                                            uint8_t* nrcellid_buf,
                                            long *dl_prbs,
@@ -1113,25 +1148,22 @@ void encode_kpm_report_style1_parameterized(E2SM_KPM_IndicationMessage_t* indica
 
   FQIPERSlicesPerPlmnPerCellListItem_t *fqi_item =
     (FQIPERSlicesPerPlmnPerCellListItem_t*)calloc(1,sizeof(FQIPERSlicesPerPlmnPerCellListItem_t));
+
+  long *p_dl_prb_usage = (long*)calloc(1, sizeof(long));
+  long *p_ul_prb_usage = (long*)calloc(1, sizeof(long));
+  *p_dl_prb_usage = (long)dl_prb_usage;
+  *p_ul_prb_usage = (long)ul_prb_usage;
+
   fqi_item->fiveQI = fiveqi;
-  fqi_item->dl_PRBUsage = &dl_prb_usage;
-  fqi_item->ul_PRBUsage = &ul_prb_usage;
+  fqi_item->dl_PRBUsage = p_dl_prb_usage;
+  fqi_item->ul_PRBUsage = p_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 +1180,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 +1194,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 +1213,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 +1222,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 +1235,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,9 +1252,10 @@ 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 = (char*)calloc(300, sizeof(char));
-  size_t errlen;
+  char error_buf[300] = {0, };
+  size_t errlen = 0;
 
   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
   printf("error length %d\n", errlen);
@@ -1225,10 +1264,10 @@ void encode_kpm_report_style1_parameterized(E2SM_KPM_IndicationMessage_t* indica
   xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
   
 
-  uint8_t e2smbuffer[8192];
+  uint8_t e2smbuffer[8192] = {0, };
   size_t e2smbuffer_size = 8192;
 
-  uint8_t e2smbuffer2[8192];
+  uint8_t e2smbuffer2[8192] = {0, };
   size_t e2smbuffer_size2 = 8192;  
 
   asn_enc_rval_t er =
@@ -1259,20 +1298,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 +1318,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 +1350,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 +1361,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 +1374,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,9 +1391,10 @@ 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 = (char*)calloc(300, sizeof(char));
-  size_t errlen;
+  char error_buf[300] = {0, };
+  size_t errlen = 0;
 
   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
   printf("error length %d\n", errlen);
@@ -1368,10 +1403,10 @@ void encode_kpm_report_style1(E2SM_KPM_IndicationMessage_t* indicationmessage) {
   xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
   
 
-  uint8_t e2smbuffer[8192];
+  uint8_t e2smbuffer[8192] = {0, };
   size_t e2smbuffer_size = 8192;
 
-  uint8_t e2smbuffer2[8192];
+  uint8_t e2smbuffer2[8192] = {0, };
   size_t e2smbuffer_size2 = 8192;  
 
   asn_enc_rval_t er =
@@ -1509,18 +1544,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,11 +1562,12 @@ 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;  
 
 
-  uint8_t e2smbuffera[8192];
+  uint8_t e2smbuffera[8192] = {0, };
   size_t e2smbuffer_sizea = 8192;
 
 
@@ -1576,6 +1601,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 +1614,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 +1627,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,9 +1644,10 @@ 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 = (char*)calloc(300, sizeof(char));
-  size_t errlen;
+  char error_buf[300] = {0, };
+  size_t errlen = 0;
 
   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
   printf("error length %d\n", errlen);
@@ -1627,10 +1656,10 @@ void encode_kpm_report_style5_parameterized(E2SM_KPM_IndicationMessage_t* indica
   xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
   
 
-  uint8_t e2smbuffer[8192];
+  uint8_t e2smbuffer[8192] = {0, };
   size_t e2smbuffer_size = 8192;
 
-  uint8_t e2smbuffer2[8192];
+  uint8_t e2smbuffer2[8192] = {0, };
   size_t e2smbuffer_size2 = 8192;  
 
   asn_enc_rval_t er =
@@ -1679,18 +1708,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,11 +1726,12 @@ 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;  
 
 
-  uint8_t e2smbuffera[8192];
+  uint8_t e2smbuffera[8192] = {0, };
   size_t e2smbuffer_sizea = 8192;
 
 
@@ -1758,6 +1777,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 +1790,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,9 +1807,10 @@ 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 = (char*)calloc(300, sizeof(char));
-  size_t errlen;
+  char error_buf[300] = {0, };
+  size_t errlen = 0;
 
   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
   printf("error length %d\n", errlen);
@@ -1797,10 +1819,10 @@ void encode_kpm_report_style5(E2SM_KPM_IndicationMessage_t* indicationmessage) {
   xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
   
 
-  uint8_t e2smbuffer[8192];
+  uint8_t e2smbuffer[8192] = {0, };
   size_t e2smbuffer_size = 8192;
 
-  uint8_t e2smbuffer2[8192];
+  uint8_t e2smbuffer2[8192] = {0, };
   size_t e2smbuffer_size2 = 8192;  
 
   asn_enc_rval_t er =