summaryrefslogtreecommitdiff
path: root/src/mem
diff options
context:
space:
mode:
authorAndreas Hansson <andreas.hansson@arm.com>2014-09-27 09:08:29 -0400
committerAndreas Hansson <andreas.hansson@arm.com>2014-09-27 09:08:29 -0400
commitde62aedabc96e7492c40bbc4468ba42b3274bfd6 (patch)
treee68dae6dd1f3da0e7d2dcf3e946728c46e63bbce /src/mem
parent71d5f03175b3a684b94bbc515ebc02e2b493b7cf (diff)
downloadgem5-de62aedabc96e7492c40bbc4468ba42b3274bfd6.tar.xz
misc: Fix a bunch of minor issues identified by static analysis
Add some missing initialisation, and fix a handful benign resource leaks (including some false positives).
Diffstat (limited to 'src/mem')
-rw-r--r--src/mem/cache/cache_impl.hh3
-rw-r--r--src/mem/comm_monitor.cc6
-rw-r--r--src/mem/comm_monitor.hh2
-rw-r--r--src/mem/packet.hh2
-rw-r--r--src/mem/physical.cc22
-rw-r--r--src/mem/ruby/system/RubyPort.cc6
6 files changed, 20 insertions, 21 deletions
diff --git a/src/mem/cache/cache_impl.hh b/src/mem/cache/cache_impl.hh
index e4a6f3c24..5cfe7c0cf 100644
--- a/src/mem/cache/cache_impl.hh
+++ b/src/mem/cache/cache_impl.hh
@@ -917,6 +917,9 @@ Cache<TagStore>::recvAtomic(PacketPtr pkt)
if (pkt->cmd == MemCmd::WriteInvalidateReq) {
memSidePort->sendAtomic(pkt); // complete writeback
if (isTopLevel) {
+ // @todo Static analysis suggests this can actually happen
+ assert(blk);
+
// top level caches allocate and write the data
assert(blk->isDirty());
assert(!blk->isWritable());
diff --git a/src/mem/comm_monitor.cc b/src/mem/comm_monitor.cc
index 3c3af76ea..c9cbcb143 100644
--- a/src/mem/comm_monitor.cc
+++ b/src/mem/comm_monitor.cc
@@ -105,6 +105,12 @@ CommMonitor::CommMonitor(Params* params)
name(), samplePeriodTicks, samplePeriod.msec());
}
+CommMonitor::~CommMonitor()
+{
+ // if not already done, close the stream
+ closeStreams();
+}
+
void
CommMonitor::closeStreams()
{
diff --git a/src/mem/comm_monitor.hh b/src/mem/comm_monitor.hh
index c3a970940..69122cc60 100644
--- a/src/mem/comm_monitor.hh
+++ b/src/mem/comm_monitor.hh
@@ -77,7 +77,7 @@ class CommMonitor : public MemObject
CommMonitor(Params* params);
/** Destructor */
- ~CommMonitor() {}
+ ~CommMonitor();
/**
* Callback to flush and close all open output streams on exit. If
diff --git a/src/mem/packet.hh b/src/mem/packet.hh
index 4ed307f66..c7b47c0a7 100644
--- a/src/mem/packet.hh
+++ b/src/mem/packet.hh
@@ -601,7 +601,7 @@ class Packet : public Printable
*/
Packet(Request *_req, MemCmd _cmd)
: cmd(_cmd), req(_req), data(nullptr), addr(0), _isSecure(false),
- src(InvalidPortID), dest(InvalidPortID),
+ size(0), src(InvalidPortID), dest(InvalidPortID),
bytesValidStart(0), bytesValidEnd(0),
firstWordDelay(0), lastWordDelay(0),
senderState(NULL)
diff --git a/src/mem/physical.cc b/src/mem/physical.cc
index 08ec83410..398d0530f 100644
--- a/src/mem/physical.cc
+++ b/src/mem/physical.cc
@@ -307,16 +307,9 @@ PhysicalMemory::serializeStore(ostream& os, unsigned int store_id,
// write memory file
string filepath = Checkpoint::dir() + "/" + filename.c_str();
- int fd = creat(filepath.c_str(), 0664);
- if (fd < 0) {
- perror("creat");
- fatal("Can't open physical memory checkpoint file '%s'\n",
- filename);
- }
-
- gzFile compressed_mem = gzdopen(fd, "wb");
+ gzFile compressed_mem = gzopen(filepath.c_str(), "wb");
if (compressed_mem == NULL)
- fatal("Insufficient memory to allocate compression state for %s\n",
+ fatal("Can't open physical memory checkpoint file '%s'\n",
filename);
uint64_t pass_size = 0;
@@ -380,16 +373,9 @@ PhysicalMemory::unserializeStore(Checkpoint* cp, const string& section)
string filepath = cp->cptDir + "/" + filename;
// mmap memoryfile
- int fd = open(filepath.c_str(), O_RDONLY);
- if (fd < 0) {
- perror("open");
- fatal("Can't open physical memory checkpoint file '%s'", filename);
- }
-
- gzFile compressed_mem = gzdopen(fd, "rb");
+ gzFile compressed_mem = gzopen(filepath.c_str(), "rb");
if (compressed_mem == NULL)
- fatal("Insufficient memory to allocate compression state for %s\n",
- filename);
+ fatal("Can't open physical memory checkpoint file '%s'", filename);
// we've already got the actual backing store mapped
uint8_t* pmem = backingStore[store_id].second;
diff --git a/src/mem/ruby/system/RubyPort.cc b/src/mem/ruby/system/RubyPort.cc
index 110b6924d..71b08ebbb 100644
--- a/src/mem/ruby/system/RubyPort.cc
+++ b/src/mem/ruby/system/RubyPort.cc
@@ -205,7 +205,11 @@ RubyPort::PioSlavePort::recvTimingReq(PacketPtr pkt)
AddrRangeList l = ruby_port->master_ports[i]->getAddrRanges();
for (auto it = l.begin(); it != l.end(); ++it) {
if (it->contains(pkt->getAddr())) {
- ruby_port->master_ports[i]->sendTimingReq(pkt);
+ // generally it is not safe to assume success here as
+ // the port could be blocked
+ bool M5_VAR_USED success =
+ ruby_port->master_ports[i]->sendTimingReq(pkt);
+ assert(success);
return true;
}
}