From fb44de80170b4845036bd3c38c26086bbc0ed02d Mon Sep 17 00:00:00 2001 From: Blaise Tine Date: Tue, 21 Jul 2020 06:17:41 -0700 Subject: [PATCH] fixed simulator leak --- hw/simulate/simulator.cpp | 10 ++++------ hw/simulate/simulator.h | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/hw/simulate/simulator.cpp b/hw/simulate/simulator.cpp index 213712a0..3f9f240e 100644 --- a/hw/simulate/simulator.cpp +++ b/hw/simulate/simulator.cpp @@ -11,7 +11,7 @@ double sc_time_stamp() { Simulator::Simulator() { // force random values for unitialized signals - Verilated::randReset(2); + Verilated::randReset(1); // Turn off assertion before reset Verilated::assertOn(false); @@ -105,9 +105,8 @@ void Simulator::eval_dram_bus() { if (!dram_rsp_active_) { if (dequeue_index != -1) { vortex_->dram_rsp_valid = 1; - memcpy((uint8_t*)vortex_->dram_rsp_data, dram_rsp_vec_[dequeue_index].data, GLOBAL_BLOCK_SIZE); - vortex_->dram_rsp_tag = dram_rsp_vec_[dequeue_index].tag; - free(dram_rsp_vec_[dequeue_index].data); + memcpy((uint8_t*)vortex_->dram_rsp_data, dram_rsp_vec_[dequeue_index].block.data(), GLOBAL_BLOCK_SIZE); + vortex_->dram_rsp_tag = dram_rsp_vec_[dequeue_index].tag; dram_rsp_vec_.erase(dram_rsp_vec_.begin() + dequeue_index); dram_rsp_active_ = true; } else { @@ -141,9 +140,8 @@ void Simulator::eval_dram_bus() { } else { dram_req_t dram_req; dram_req.cycles_left = DRAM_LATENCY; - dram_req.data = (uint8_t*)malloc(GLOBAL_BLOCK_SIZE); dram_req.tag = vortex_->dram_req_tag; - ram_->read(vortex_->dram_req_addr * GLOBAL_BLOCK_SIZE, GLOBAL_BLOCK_SIZE, dram_req.data); + ram_->read(vortex_->dram_req_addr * GLOBAL_BLOCK_SIZE, GLOBAL_BLOCK_SIZE, dram_req.block.data()); dram_rsp_vec_.push_back(dram_req); } } diff --git a/hw/simulate/simulator.h b/hw/simulate/simulator.h index 297e2121..7fb6370a 100644 --- a/hw/simulate/simulator.h +++ b/hw/simulate/simulator.h @@ -21,7 +21,7 @@ typedef struct { int cycles_left; - uint8_t *data; + std::array block; unsigned tag; } dram_req_t;