From 8f850754f3ca6f7fd7f6a4b9dd89f171e0455702 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 6 Feb 2018 16:42:43 +0100 Subject: [PATCH] check malloc return value in various tests --- lib/src/phy/phch/test/pdsch_pdcch_file_test.c | 7 ++++++- lib/src/phy/phch/test/pmch_file_test.c | 12 +++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/src/phy/phch/test/pdsch_pdcch_file_test.c b/lib/src/phy/phch/test/pdsch_pdcch_file_test.c index 76f48b959..baab97cea 100644 --- a/lib/src/phy/phch/test/pdsch_pdcch_file_test.c +++ b/lib/src/phy/phch/test/pdsch_pdcch_file_test.c @@ -175,6 +175,10 @@ int main(int argc, char **argv) { } uint8_t *data[] = {malloc(100000)}; + if (!data[0]) { + perror("malloc"); + exit(-1); + } ret = -1; nof_frames = 0; @@ -195,7 +199,8 @@ int main(int argc, char **argv) { } while (nof_frames <= max_frames && ret == 0); base_free(); - free(data[0]); + if (data[0]) + free(data[0]); if (ret > 0) { exit(0); } else { diff --git a/lib/src/phy/phch/test/pmch_file_test.c b/lib/src/phy/phch/test/pmch_file_test.c index 1d0715caa..fa6d04092 100644 --- a/lib/src/phy/phch/test/pmch_file_test.c +++ b/lib/src/phy/phch/test/pmch_file_test.c @@ -181,13 +181,17 @@ int main(int argc, char **argv) { exit(-1); } - uint8_t *data[] = {malloc(100000)}; + uint8_t *data = malloc(100000); + if (!data) { + perror("malloc"); + exit(-1); + } ret = -1; srslte_filesource_read(&fsrc, input_buffer[0], flen); INFO("Reading %d samples sub-frame %d\n", flen, sf_idx); - ret = srslte_ue_dl_decode_mbsfn(&ue_dl, data[0], sf_idx); + ret = srslte_ue_dl_decode_mbsfn(&ue_dl, data, sf_idx); if(ret > 0) { printf("PMCH Decoded OK!\n"); } else if (ret < 0) { @@ -195,7 +199,9 @@ int main(int argc, char **argv) { } base_free(); - free(data[0]); + if (data != NULL) { + free(data); + } if (ret > 0) { exit(0); } else {