From ccfb9314bc0f248204963d10e60005fed5e46e46 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Sun, 11 Feb 2018 10:59:56 +0100 Subject: [PATCH] fix various coverity bugs --- lib/src/common/logger_file.cc | 2 +- lib/src/phy/utils/ringbuffer.c | 2 ++ lib/src/upper/rlc_am.cc | 2 +- lib/test/upper/rlc_am_stress_test.cc | 1 + srsue/hdr/upper/rrc.h | 12 +++++++++--- srsue/src/upper/rrc.cc | 8 ++++++++ 6 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/src/common/logger_file.cc b/lib/src/common/logger_file.cc index f7532fdd1..25155da08 100644 --- a/lib/src/common/logger_file.cc +++ b/lib/src/common/logger_file.cc @@ -54,7 +54,7 @@ void logger_file::init(std::string file, int max_length_) { pthread_mutex_init(&mutex, NULL); pthread_cond_init(¬_empty, NULL); pthread_cond_init(¬_full, NULL); - max_length = max_length_*1024; + max_length = (int64_t)max_length_*1024; name_idx = 0; filename = file; logfile = fopen(filename.c_str(), "w"); diff --git a/lib/src/phy/utils/ringbuffer.c b/lib/src/phy/utils/ringbuffer.c index d5f99fd87..8f0c3edf2 100644 --- a/lib/src/phy/utils/ringbuffer.c +++ b/lib/src/phy/utils/ringbuffer.c @@ -54,6 +54,7 @@ int srslte_ringbuffer_write(srslte_ringbuffer_t *q, void *p, int nof_bytes) int w_bytes = nof_bytes; pthread_mutex_lock(&q->mutex); if (!q->active) { + pthread_mutex_unlock(&q->mutex); return 0; } if (q->count + w_bytes > q->capacity) { @@ -85,6 +86,7 @@ int srslte_ringbuffer_read(srslte_ringbuffer_t *q, void *p, int nof_bytes) pthread_cond_wait(&q->cvar, &q->mutex); } if (!q->active) { + pthread_mutex_unlock(&q->mutex); return 0; } if (nof_bytes + q->rpm > q->capacity) { diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index 2c8b1fbfc..e4a6242fa 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -1085,11 +1085,11 @@ void rlc_am::handle_control_pdu(uint8_t *payload, uint32_t nof_bytes) it = tx_window.find(i); if (it != tx_window.end()) { if(update_vt_a) { - tx_window.erase(it); if(it->second.buf) { pool->deallocate(it->second.buf); it->second.buf = 0; } + tx_window.erase(it); vt_a = (vt_a + 1)%MOD; vt_ms = (vt_ms + 1)%MOD; } diff --git a/lib/test/upper/rlc_am_stress_test.cc b/lib/test/upper/rlc_am_stress_test.cc index d6fb0882d..548feb818 100644 --- a/lib/test/upper/rlc_am_stress_test.cc +++ b/lib/test/upper/rlc_am_stress_test.cc @@ -47,6 +47,7 @@ public: rlc2 = rlc2_; fail_rate = fail_rate_; run_enable = true; + running = false; } void stop() diff --git a/srsue/hdr/upper/rrc.h b/srsue/hdr/upper/rrc.h index 27764bd02..4ac2dfa2f 100644 --- a/srsue/hdr/upper/rrc.h +++ b/srsue/hdr/upper/rrc.h @@ -76,17 +76,22 @@ class cell_t return false; } cell_t() { - this->has_valid_sib1 = false; - this->has_valid_sib2 = false; - this->has_valid_sib3 = false; + srslte_cell_t tmp = {}; + cell_t(tmp, 0, 0); } cell_t(srslte_cell_t phy_cell, uint32_t earfcn, float rsrp) { this->has_valid_sib1 = false; this->has_valid_sib2 = false; this->has_valid_sib3 = false; + this->has_valid_sib13 = false; this->phy_cell = phy_cell; this->rsrp = rsrp; this->earfcn = earfcn; + in_sync = false; + bzero(&sib1, sizeof(sib1)); + bzero(&sib2, sizeof(sib2)); + bzero(&sib3, sizeof(sib3)); + bzero(&sib13, sizeof(sib13)); } uint32_t earfcn; @@ -114,6 +119,7 @@ class rrc { public: rrc(); + ~rrc(); void init(phy_interface_rrc *phy_, mac_interface_rrc *mac_, diff --git a/srsue/src/upper/rrc.cc b/srsue/src/upper/rrc.cc index 24ccbb4c0..ad5cf29b2 100644 --- a/srsue/src/upper/rrc.cc +++ b/srsue/src/upper/rrc.cc @@ -49,12 +49,20 @@ rrc::rrc() :state(RRC_STATE_IDLE) ,drb_up(false) ,sysinfo_index(0) + ,serving_cell(NULL) { n310_cnt = 0; n311_cnt = 0; serving_cell = new cell_t(); } +rrc::~rrc() +{ + if (serving_cell) { + delete(serving_cell); + } +} + static void liblte_rrc_handler(void *ctx, char *str) { rrc *r = (rrc *) ctx; r->liblte_rrc_log(str);