diff --git a/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac.c b/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac.c index 656cedfe62..7bdeaaec12 100644 --- a/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac.c +++ b/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac.c @@ -192,8 +192,14 @@ int flexran_agent_mac_stats_reply(mid_t mod_id, for (j = 0; j < dl_report->n_csi_report; j++) { csi_reports[j] = malloc(sizeof(Protocol__FlexDlCsi)); - if (csi_reports[j] == NULL) + if (csi_reports[j] == NULL) { + for (k = 0; k < j; k++) { + free(csi_reports[k]); + } + free(csi_reports); + csi_reports = NULL; goto error; + } protocol__flex_dl_csi__init(csi_reports[j]); //The servCellIndex for this report csi_reports[j]->serv_cell_index = j; @@ -213,8 +219,14 @@ int flexran_agent_mac_stats_reply(mid_t mod_id, Protocol__FlexCsiP10 *csi10; csi10 = malloc(sizeof(Protocol__FlexCsiP10)); - if (csi10 == NULL) - goto error; + if (csi10 == NULL) { + for (k = 0; k <= j; k++) { + free(csi_reports[k]); + } + free(csi_reports); + csi_reports = NULL; + goto error; + } protocol__flex_csi_p10__init(csi10); //TODO: set the wideband value // NN: this is also depends on cc_id @@ -229,8 +241,14 @@ int flexran_agent_mac_stats_reply(mid_t mod_id, Protocol__FlexCsiP11 *csi11; csi11 = malloc(sizeof(Protocol__FlexCsiP11)); - if (csi11 == NULL) - goto error; + if (csi11 == NULL) { + for (k = 0; k <= j; k++) { + free(csi_reports[k]); + } + free(csi_reports); + csi_reports = NULL; + goto error; + } protocol__flex_csi_p11__init(csi11); csi11->wb_cqi = malloc(sizeof(csi11->wb_cqi)); @@ -274,8 +292,14 @@ int flexran_agent_mac_stats_reply(mid_t mod_id, Protocol__FlexCsiP20 *csi20; csi20 = malloc(sizeof(Protocol__FlexCsiP20)); - if (csi20 == NULL) - goto error; + if (csi20 == NULL) { + for (k = 0; k <= j; k++) { + free(csi_reports[k]); + } + free(csi_reports); + csi_reports = NULL; + goto error; + } protocol__flex_csi_p20__init(csi20); csi20->wb_cqi = flexran_get_ue_wcqi (enb_id, UE_id);