changeset 6400a2ab4e22 in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=6400a2ab4e22
description:
        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:

 src/base/output.cc                     |   2 ++
 src/base/socket.cc                     |   7 +++++--
 src/cpu/testers/rubytest/RubyTester.cc |   3 +++
 src/mem/cache/cache_impl.hh            |   3 +++
 src/mem/comm_monitor.cc                |   6 ++++++
 src/mem/comm_monitor.hh                |   2 +-
 src/mem/packet.hh                      |   2 +-
 src/mem/physical.cc                    |  22 ++++------------------
 src/mem/ruby/system/RubyPort.cc        |   6 +++++-
 src/sim/eventq.cc                      |  11 +++++------
 src/sim/eventq.hh                      |   3 ++-
 11 files changed, 37 insertions(+), 30 deletions(-)

diffs (222 lines):

diff -r d96740732a61 -r 6400a2ab4e22 src/base/output.cc
--- a/src/base/output.cc        Sun Sep 21 23:04:39 2014 -0400
+++ b/src/base/output.cc        Sat Sep 27 09:08:29 2014 -0400
@@ -255,6 +255,8 @@
 
                 de = readdir(subdir);
             }
+
+            closedir(subdir);
         }
 
         // try to force recognition that we deleted the files in the directory
diff -r d96740732a61 -r 6400a2ab4e22 src/base/socket.cc
--- a/src/base/socket.cc        Sun Sep 21 23:04:39 2014 -0400
+++ b/src/base/socket.cc        Sat Sep 27 09:08:29 2014 -0400
@@ -94,8 +94,9 @@
     struct sockaddr_in sockaddr;
     sockaddr.sin_family = PF_INET;
     sockaddr.sin_addr.s_addr = INADDR_ANY;
-
     sockaddr.sin_port = htons(port);
+    // finally clear sin_zero
+    memset(&sockaddr.sin_zero, 0, sizeof(sockaddr.sin_zero));
     int ret = ::bind(fd, (struct sockaddr *)&sockaddr, sizeof (sockaddr));
     if (ret != 0) {
         if (ret == -1 && errno != EADDRINUSE)
@@ -126,7 +127,9 @@
     int sfd = ::accept(fd, (struct sockaddr *)&sockaddr, &slen);
     if (sfd != -1 && nodelay) {
         int i = 1;
-        ::setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, (char *)&i, sizeof(i));
+        if (::setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, (char *)&i,
+                         sizeof(i)) < 0)
+            warn("ListenSocket(accept): setsockopt() TCP_NODELAY failed!");
     }
 
     return sfd;
diff -r d96740732a61 -r 6400a2ab4e22 src/cpu/testers/rubytest/RubyTester.cc
--- a/src/cpu/testers/rubytest/RubyTester.cc    Sun Sep 21 23:04:39 2014 -0400
+++ b/src/cpu/testers/rubytest/RubyTester.cc    Sat Sep 27 09:08:29 2014 -0400
@@ -52,9 +52,12 @@
 RubyTester::RubyTester(const Params *p)
   : MemObject(p), checkStartEvent(this),
     _masterId(p->system->getMasterId(name())),
+    m_checkTable_ptr(nullptr),
     m_num_cpus(p->num_cpus),
     m_checks_to_complete(p->checks_to_complete),
     m_deadlock_threshold(p->deadlock_threshold),
+    m_num_writers(0),
+    m_num_readers(0),
     m_wakeup_frequency(p->wakeup_frequency),
     m_check_flush(p->check_flush),
     m_num_inst_ports(p->port_cpuInstPort_connection_count)
diff -r d96740732a61 -r 6400a2ab4e22 src/mem/cache/cache_impl.hh
--- a/src/mem/cache/cache_impl.hh       Sun Sep 21 23:04:39 2014 -0400
+++ b/src/mem/cache/cache_impl.hh       Sat Sep 27 09:08:29 2014 -0400
@@ -917,6 +917,9 @@
     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 -r d96740732a61 -r 6400a2ab4e22 src/mem/comm_monitor.cc
--- a/src/mem/comm_monitor.cc   Sun Sep 21 23:04:39 2014 -0400
+++ b/src/mem/comm_monitor.cc   Sat Sep 27 09:08:29 2014 -0400
@@ -105,6 +105,12 @@
             name(), samplePeriodTicks, samplePeriod.msec());
 }
 
+CommMonitor::~CommMonitor()
+{
+    // if not already done, close the stream
+    closeStreams();
+}
+
 void
 CommMonitor::closeStreams()
 {
diff -r d96740732a61 -r 6400a2ab4e22 src/mem/comm_monitor.hh
--- a/src/mem/comm_monitor.hh   Sun Sep 21 23:04:39 2014 -0400
+++ b/src/mem/comm_monitor.hh   Sat Sep 27 09:08:29 2014 -0400
@@ -77,7 +77,7 @@
     CommMonitor(Params* params);
 
     /** Destructor */
-    ~CommMonitor() {}
+    ~CommMonitor();
 
     /**
      * Callback to flush and close all open output streams on exit. If
diff -r d96740732a61 -r 6400a2ab4e22 src/mem/packet.hh
--- a/src/mem/packet.hh Sun Sep 21 23:04:39 2014 -0400
+++ b/src/mem/packet.hh Sat Sep 27 09:08:29 2014 -0400
@@ -601,7 +601,7 @@
      */
     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 -r d96740732a61 -r 6400a2ab4e22 src/mem/physical.cc
--- a/src/mem/physical.cc       Sun Sep 21 23:04:39 2014 -0400
+++ b/src/mem/physical.cc       Sat Sep 27 09:08:29 2014 -0400
@@ -307,17 +307,10 @@
 
     // write memory file
     string filepath = Checkpoint::dir() + "/" + filename.c_str();
-    int fd = creat(filepath.c_str(), 0664);
-    if (fd < 0) {
-        perror("creat");
+    gzFile compressed_mem = gzopen(filepath.c_str(), "wb");
+    if (compressed_mem == NULL)
         fatal("Can't open physical memory checkpoint file '%s'\n",
               filename);
-    }
-
-    gzFile compressed_mem = gzdopen(fd, "wb");
-    if (compressed_mem == NULL)
-        fatal("Insufficient memory to allocate compression state for %s\n",
-              filename);
 
     uint64_t pass_size = 0;
 
@@ -380,16 +373,9 @@
     string filepath = cp->cptDir + "/" + filename;
 
     // mmap memoryfile
-    int fd = open(filepath.c_str(), O_RDONLY);
-    if (fd < 0) {
-        perror("open");
+    gzFile compressed_mem = gzopen(filepath.c_str(), "rb");
+    if (compressed_mem == NULL)
         fatal("Can't open physical memory checkpoint file '%s'", filename);
-    }
-
-    gzFile compressed_mem = gzdopen(fd, "rb");
-    if (compressed_mem == NULL)
-        fatal("Insufficient memory to allocate compression state for %s\n",
-              filename);
 
     // we've already got the actual backing store mapped
     uint8_t* pmem = backingStore[store_id].second;
diff -r d96740732a61 -r 6400a2ab4e22 src/mem/ruby/system/RubyPort.cc
--- a/src/mem/ruby/system/RubyPort.cc   Sun Sep 21 23:04:39 2014 -0400
+++ b/src/mem/ruby/system/RubyPort.cc   Sat Sep 27 09:08:29 2014 -0400
@@ -205,7 +205,11 @@
         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;
             }
         }
diff -r d96740732a61 -r 6400a2ab4e22 src/sim/eventq.cc
--- a/src/sim/eventq.cc Sun Sep 21 23:04:39 2014 -0400
+++ b/src/sim/eventq.cc Sat Sep 27 09:08:29 2014 -0400
@@ -460,29 +460,28 @@
 }
 
 EventQueue::EventQueue(const string &n)
-    : objName(n), head(NULL), _curTick(0),
-    async_queue_mutex(new std::mutex())
+    : objName(n), head(NULL), _curTick(0)
 {
 }
 
 void
 EventQueue::asyncInsert(Event *event)
 {
-    async_queue_mutex->lock();
+    async_queue_mutex.lock();
     async_queue.push_back(event);
-    async_queue_mutex->unlock();
+    async_queue_mutex.unlock();
 }
 
 void
 EventQueue::handleAsyncInsertions()
 {
     assert(this == curEventQueue());
-    async_queue_mutex->lock();
+    async_queue_mutex.lock();
 
     while (!async_queue.empty()) {
         insert(async_queue.front());
         async_queue.pop_front();
     }
 
-    async_queue_mutex->unlock();
+    async_queue_mutex.unlock();
 }
diff -r d96740732a61 -r 6400a2ab4e22 src/sim/eventq.hh
--- a/src/sim/eventq.hh Sun Sep 21 23:04:39 2014 -0400
+++ b/src/sim/eventq.hh Sat Sep 27 09:08:29 2014 -0400
@@ -42,6 +42,7 @@
 #include <cassert>
 #include <climits>
 #include <iosfwd>
+#include <memory>
 #include <mutex>
 #include <string>
 
@@ -448,7 +449,7 @@
     Tick _curTick;
 
     //! Mutex to protect async queue.
-    std::mutex *async_queue_mutex;
+    std::mutex async_queue_mutex;
 
     //! List of events added by other threads to this event queue.
     std::list<Event*> async_queue;
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to