fix memleaks and uninitialized vars found by cppcheck

master
Andre Puschmann 5 years ago
parent d7d3233bde
commit a2ab043c0d

@ -606,13 +606,13 @@ int main(int argc, char **argv) {
dl_sf.tdd_config.configured = true; dl_sf.tdd_config.configured = true;
} }
srslte_chest_dl_cfg_t chest_pdsch_cfg; srslte_chest_dl_cfg_t chest_pdsch_cfg = {};
chest_pdsch_cfg.cfo_estimate_enable = prog_args.enable_cfo_ref; chest_pdsch_cfg.cfo_estimate_enable = prog_args.enable_cfo_ref;
chest_pdsch_cfg.cfo_estimate_sf_mask = 1023; chest_pdsch_cfg.cfo_estimate_sf_mask = 1023;
chest_pdsch_cfg.interpolate_subframe = !prog_args.average_subframe; chest_pdsch_cfg.interpolate_subframe = !prog_args.average_subframe;
// Special configuration for MBSFN channel estimation // Special configuration for MBSFN channel estimation
srslte_chest_dl_cfg_t chest_mbsfn_cfg; srslte_chest_dl_cfg_t chest_mbsfn_cfg = {};
chest_mbsfn_cfg.filter_type = SRSLTE_CHEST_FILTER_TRIANGLE; chest_mbsfn_cfg.filter_type = SRSLTE_CHEST_FILTER_TRIANGLE;
chest_mbsfn_cfg.filter_coef[0] = 0.1; chest_mbsfn_cfg.filter_coef[0] = 0.1;
chest_mbsfn_cfg.interpolate_subframe = true; chest_mbsfn_cfg.interpolate_subframe = true;

@ -52,7 +52,7 @@ void srslte_filesource_seek(srslte_filesource_t *q, int pos) {
int read_complex_f(FILE *f, _Complex float *y) { int read_complex_f(FILE *f, _Complex float *y) {
char in_str[64]; char in_str[64];
_Complex float x; _Complex float x = 0;
if (NULL == fgets(in_str, 64, f)) { if (NULL == fgets(in_str, 64, f)) {
return -1; return -1;
} else { } else {

@ -86,8 +86,8 @@ void parse_args(int argc, char** argv)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
cf_t* fft_buffer; cf_t* fft_buffer = NULL;
cf_t* buffer; cf_t* buffer = NULL;
srslte_nsss_synch_t syncobj; srslte_nsss_synch_t syncobj;
srslte_ofdm_t ifft; srslte_ofdm_t ifft;
int fft_size; int fft_size;
@ -107,20 +107,20 @@ int main(int argc, char** argv)
fft_size = srslte_symbol_sz(NOF_PRB); fft_size = srslte_symbol_sz(NOF_PRB);
if (fft_size < 0) { if (fft_size < 0) {
fprintf(stderr, "Invalid nof_prb=%d\n", NOF_PRB); fprintf(stderr, "Invalid nof_prb=%d\n", NOF_PRB);
return ret; goto exit;
} }
printf("SFLEN is %d samples\n", SFLEN); printf("SFLEN is %d samples\n", SFLEN);
fft_buffer = malloc(sizeof(cf_t) * SFLEN * max_num_sf); fft_buffer = malloc(sizeof(cf_t) * SFLEN * max_num_sf);
if (!fft_buffer) { if (!fft_buffer) {
perror("malloc"); perror("malloc");
return ret; goto exit;
} }
memset(fft_buffer, 0, sizeof(cf_t) * SFLEN * max_num_sf); memset(fft_buffer, 0, sizeof(cf_t) * SFLEN * max_num_sf);
if (srslte_ofdm_tx_init(&ifft, SRSLTE_CP_NORM, buffer, fft_buffer, NOF_PRB)) { if (srslte_ofdm_tx_init(&ifft, SRSLTE_CP_NORM, buffer, fft_buffer, NOF_PRB)) {
fprintf(stderr, "Error creating iFFT object\n"); fprintf(stderr, "Error creating iFFT object\n");
return ret; goto exit;
} }
if (input_file_name != NULL) { if (input_file_name != NULL) {
@ -128,7 +128,7 @@ int main(int argc, char** argv)
printf("Opening file %s\n", input_file_name); printf("Opening file %s\n", input_file_name);
if (srslte_filesource_init(&fsrc, input_file_name, SRSLTE_COMPLEX_FLOAT_BIN)) { if (srslte_filesource_init(&fsrc, input_file_name, SRSLTE_COMPLEX_FLOAT_BIN)) {
fprintf(stderr, "Error opening file %s\n", input_file_name); fprintf(stderr, "Error opening file %s\n", input_file_name);
return ret; goto exit;
} }
num_sf = 0; num_sf = 0;
@ -141,7 +141,7 @@ int main(int argc, char** argv)
int n = srslte_filesource_read(&fsrc, &fft_buffer[num_sf * SFLEN], SFLEN); int n = srslte_filesource_read(&fsrc, &fft_buffer[num_sf * SFLEN], SFLEN);
if (n < 0) { if (n < 0) {
fprintf(stderr, "Error reading samples\n"); fprintf(stderr, "Error reading samples\n");
return ret; goto exit;
} }
if (n < SFLEN) { if (n < SFLEN) {
fprintf(stdout, "End of file (n=%d, sflen=%d)\n", n, SFLEN); fprintf(stdout, "End of file (n=%d, sflen=%d)\n", n, SFLEN);
@ -157,7 +157,7 @@ int main(int argc, char** argv)
printf("Initializing NSSS synch with %dx%d samples.\n", num_sf, SFLEN); printf("Initializing NSSS synch with %dx%d samples.\n", num_sf, SFLEN);
if (srslte_nsss_synch_init(&syncobj, num_sf * SFLEN, fft_size)) { if (srslte_nsss_synch_init(&syncobj, num_sf * SFLEN, fft_size)) {
fprintf(stderr, "Error initializing NSSS object\n"); fprintf(stderr, "Error initializing NSSS object\n");
return ret; goto exit;
} }
// write single NSSS sequence if not reading from input file // write single NSSS sequence if not reading from input file
@ -214,10 +214,16 @@ int main(int argc, char** argv)
#endif #endif
// cleanup // cleanup
exit:
srslte_nsss_synch_free(&syncobj); srslte_nsss_synch_free(&syncobj);
free(buffer);
free(fft_buffer);
srslte_ofdm_tx_free(&ifft); srslte_ofdm_tx_free(&ifft);
if (buffer) {
free(buffer);
}
if (fft_buffer) {
free(fft_buffer);
}
return ret; return ret;
} }

@ -83,8 +83,9 @@ void parse_args(int argc, char** argv)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
int ret = SRSLTE_ERROR;
int sf_idx = 0; int sf_idx = 0;
cf_t* fft_buffer; cf_t* fft_buffer = NULL;
_Complex float buffer[SFLEN]; // FLEN + fft_size _Complex float buffer[SFLEN]; // FLEN + fft_size
srslte_filesource_t fsrc; srslte_filesource_t fsrc;
@ -102,7 +103,7 @@ int main(int argc, char** argv)
printf("Opening file...\n"); printf("Opening file...\n");
if (srslte_filesource_init(&fsrc, input_file_name, SRSLTE_COMPLEX_FLOAT_BIN)) { if (srslte_filesource_init(&fsrc, input_file_name, SRSLTE_COMPLEX_FLOAT_BIN)) {
fprintf(stderr, "Error opening file %s\n", input_file_name); fprintf(stderr, "Error opening file %s\n", input_file_name);
exit(-1); goto exit;
} }
} }
@ -116,14 +117,14 @@ int main(int argc, char** argv)
fft_buffer = malloc(sizeof(cf_t) * SFLEN * 2); fft_buffer = malloc(sizeof(cf_t) * SFLEN * 2);
if (!fft_buffer) { if (!fft_buffer) {
perror("malloc"); perror("malloc");
exit(-1); goto exit;
} }
memset(buffer, 0, sizeof(cf_t) * SFLEN); memset(buffer, 0, sizeof(cf_t) * SFLEN);
if (srslte_cfo_init(&cfocorr, SFLEN)) { if (srslte_cfo_init(&cfocorr, SFLEN)) {
fprintf(stderr, "Error initiating CFO\n"); fprintf(stderr, "Error initiating CFO\n");
return -1; goto exit;
} }
// Set a CFO tolerance of approx 100 Hz // Set a CFO tolerance of approx 100 Hz
srslte_cfo_set_tol(&cfocorr, 100.0 / (15000.0 * fft_size)); srslte_cfo_set_tol(&cfocorr, 100.0 / (15000.0 * fft_size));
@ -131,7 +132,7 @@ int main(int argc, char** argv)
// init synch object for a maximum SFLEN samples // init synch object for a maximum SFLEN samples
if (srslte_sync_nbiot_init(&syncobj, SFLEN, SFLEN, fft_size)) { if (srslte_sync_nbiot_init(&syncobj, SFLEN, SFLEN, fft_size)) {
fprintf(stderr, "Error initiating NPSS/NSSS\n"); fprintf(stderr, "Error initiating NPSS/NSSS\n");
return -1; goto exit;
} }
srslte_sync_nbiot_set_cfo_enable(&syncobj, true); srslte_sync_nbiot_set_cfo_enable(&syncobj, true);
@ -140,7 +141,7 @@ int main(int argc, char** argv)
if (srslte_ofdm_tx_init( if (srslte_ofdm_tx_init(
&ifft, SRSLTE_CP_NORM, buffer, &fft_buffer[offset], SRSLTE_NBIOT_DEFAULT_NUM_PRB_BASECELL)) { &ifft, SRSLTE_CP_NORM, buffer, &fft_buffer[offset], SRSLTE_NBIOT_DEFAULT_NUM_PRB_BASECELL)) {
fprintf(stderr, "Error creating iFFT object\n"); fprintf(stderr, "Error creating iFFT object\n");
exit(-1); goto exit;
} }
srslte_ofdm_set_normalize(&ifft, true); srslte_ofdm_set_normalize(&ifft, true);
srslte_ofdm_set_freq_shift(&ifft, -SRSLTE_NBIOT_FREQ_SHIFT_FACTOR); srslte_ofdm_set_freq_shift(&ifft, -SRSLTE_NBIOT_FREQ_SHIFT_FACTOR);
@ -162,7 +163,7 @@ int main(int argc, char** argv)
int n = srslte_filesource_read(&fsrc, fft_buffer, SFLEN); int n = srslte_filesource_read(&fsrc, fft_buffer, SFLEN);
if (n < 0) { if (n < 0) {
fprintf(stderr, "Error reading samples\n"); fprintf(stderr, "Error reading samples\n");
exit(-1); goto exit;
} }
} }
@ -204,15 +205,23 @@ int main(int argc, char** argv)
(SFLEN + SRSLTE_NPSS_CORR_FILTER_LEN - 1) * sizeof(float)); (SFLEN + SRSLTE_NPSS_CORR_FILTER_LEN - 1) * sizeof(float));
#endif #endif
printf("Ok\n");
ret = SRSLTE_SUCCESS;
// cleanup // cleanup
if (input_file_name != NULL) exit:
if (input_file_name != NULL) {
srslte_filesource_free(&fsrc); srslte_filesource_free(&fsrc);
}
srslte_sync_nbiot_free(&syncobj); srslte_sync_nbiot_free(&syncobj);
free(fft_buffer);
srslte_cfo_free(&cfocorr); srslte_cfo_free(&cfocorr);
printf("Ok\n"); if (fft_buffer) {
exit(0); free(fft_buffer);
}
return ret;
} }
void write_to_file() void write_to_file()

@ -214,7 +214,7 @@ alloc_outcome_t sched::tti_sched_t::alloc_ul(sched_ue* use
return ret; return ret;
} }
ul_alloc_t ul_alloc; ul_alloc_t ul_alloc = {};
ul_alloc.type = alloc_type; ul_alloc.type = alloc_type;
ul_alloc.dci_idx = tti_alloc.get_pdcch_grid().nof_allocs() - 1; ul_alloc.dci_idx = tti_alloc.get_pdcch_grid().nof_allocs() - 1;
ul_alloc.user_ptr = user; ul_alloc.user_ptr = user;

@ -89,8 +89,8 @@ void parse_args(all_args_t* args, int argc, char* argv[])
string mme_apn; string mme_apn;
string encryption_algo; string encryption_algo;
string integrity_algo; string integrity_algo;
uint16_t paging_timer; uint16_t paging_timer = 0;
uint32_t max_paging_queue; uint32_t max_paging_queue = 0;
string spgw_bind_addr; string spgw_bind_addr;
string sgi_if_addr; string sgi_if_addr;
string sgi_if_name; string sgi_if_name;

Loading…
Cancel
Save