Fix: Address a few benign memory leaks
authorAndreas Hansson <andreas.hansson@arm.com>
Mon, 9 Jul 2012 16:35:30 +0000 (12:35 -0400)
committerAndreas Hansson <andreas.hansson@arm.com>
Mon, 9 Jul 2012 16:35:30 +0000 (12:35 -0400)
This patch is the result of static analysis identifying a number of
memory leaks. The leaks are all benign as they are a result of not
deallocating memory in the desctructor. The fix still has value as it
removes false positives in the static analysis.

18 files changed:
src/base/loader/hex_file.cc
src/cpu/activity.cc
src/cpu/activity.hh
src/cpu/base.cc
src/cpu/o3/regfile.hh
src/dev/arm/pl111.cc
src/dev/arm/pl111.hh
src/dev/ethertap.cc
src/dev/i8254xGBe.cc
src/dev/i8254xGBe.hh
src/dev/ns_gige.cc
src/mem/cache/mshr.cc
src/mem/cache/tags/fa_lru.cc
src/mem/cache/tags/fa_lru.hh
src/mem/cache/tags/iic.cc
src/mem/page_table.cc
src/sim/serialize.cc
src/sim/serialize.hh

index bfebc1b44b54000ba5391fe128fbb6f2c9299356..e26ac31e6ed1ba417f182252cf0e4ee7af1ee727 100755 (executable)
@@ -56,6 +56,8 @@ HexFile::HexFile(const string _filename)
 
 HexFile::~HexFile()
 {
+    if (fp != NULL)
+        fclose(fp);
 }
 
 bool
index 13613cffc0a18de1c36223cc976fae8936f7bb3f..87875c683dfe7b29d833a9683eb9d53eeb9dbe63 100644 (file)
@@ -46,6 +46,11 @@ ActivityRecorder::ActivityRecorder(const string &name, int num_stages,
     std::memset(stageActive, 0, numStages);
 }
 
+ActivityRecorder::~ActivityRecorder()
+{
+    delete[] stageActive;
+}
+
 void
 ActivityRecorder::activity()
 {
index f119c95cc371deedda00fb0e1d8bdb8db872c019..7913bf5e7f4fa7b6e1454e3b8317ee7a2a8a7f71 100644 (file)
@@ -54,6 +54,7 @@ class ActivityRecorder
   public:
     ActivityRecorder(const std::string &name, int num_stages,
                      int longest_latency, int count);
+    ~ActivityRecorder();
 
     /** Records that there is activity this cycle. */
     void activity();
index c942cad443cd6d0329ce884482caa12dbbc8ae61..4017140a59cf3e6d383a03d8c1dff490c76ae069 100644 (file)
@@ -243,6 +243,9 @@ BaseCPU::enableFunctionTrace()
 
 BaseCPU::~BaseCPU()
 {
+    delete profileEvent;
+    delete[] comLoadEventQueue;
+    delete[] comInstEventQueue;
 }
 
 void
index 117c955c22934d75181aea538267331b16d3a30a..d0f50c85cf8e3634485a8212abc6ea5ce41ff6c8 100644 (file)
@@ -75,6 +75,11 @@ class PhysRegFile
     PhysRegFile(O3CPU *_cpu, unsigned _numPhysicalIntRegs,
                 unsigned _numPhysicalFloatRegs);
 
+    /**
+     * Destructor to free resources
+     */
+    ~PhysRegFile();
+
     //Everything below should be pretty well identical to the normal
     //register file that exists within AlphaISA class.
     //The duplication is unfortunate but it's better than having
@@ -197,4 +202,11 @@ PhysRegFile<Impl>::PhysRegFile(O3CPU *_cpu, unsigned _numPhysicalIntRegs,
     memset(floatRegFile, 0, sizeof(PhysFloatReg) * numPhysicalFloatRegs);
 }
 
+template <class Impl>
+PhysRegFile<Impl>::~PhysRegFile()
+{
+    delete intRegFile;
+    delete floatRegFile;
+}
+
 #endif
index 7c25958e010b7b2861d667f015f8f63b51131069..c1edc29eafe712c353526e63384689bc2c6e6955 100644 (file)
@@ -84,6 +84,11 @@ Pl111::Pl111(const Params *p)
         vncserver->setFramebufferAddr(dmaBuffer);
 }
 
+Pl111::~Pl111()
+{
+    delete[] dmaBuffer;
+}
+
 // read registers and frame buffer
 Tick
 Pl111::read(PacketPtr pkt)
index e0a03641c8c11d37b669886d8a53cae072d1eed4..36dfc46c14bdd1ba66f22d566b66a306a53219c3 100644 (file)
@@ -316,6 +316,7 @@ class Pl111: public AmbaDmaDevice
         return dynamic_cast<const Params *>(_params);
     }
     Pl111(const Params *p);
+    ~Pl111();
 
     virtual Tick read(PacketPtr pkt);
     virtual Tick write(PacketPtr pkt);
index 2a85aa524d94fc5dcc67c6e86428625b9aa174f9..94e381a8ed228b6a70bc8369479d336f84388e71 100644 (file)
@@ -147,6 +147,7 @@ EtherTap::~EtherTap()
     if (buffer)
         delete [] buffer;
 
+    delete interface;
     delete listener;
 }
 
index 29bd5adc2a92b924a5669c8547242547d723b76f..1f2c92425e8ddef3520b23732e24c641f91b7525 100644 (file)
@@ -122,6 +122,11 @@ IGbE::IGbE(const Params *p)
     txFifo.clear();
 }
 
+IGbE::~IGbE()
+{
+    delete etherInt;
+}
+
 void
 IGbE::init()
 {
@@ -827,6 +832,8 @@ template<class T>
 IGbE::DescCache<T>::~DescCache()
 {
     reset();
+    delete[] fetchBuf;
+    delete[] wbBuf;
 }
 
 template<class T>
index 7c31222ed6f4f4be670fa2c9dd02d34bff0264cc..a6b20a2bffb6d0414c8a230662dd67074fbd348c 100644 (file)
@@ -518,7 +518,7 @@ class IGbE : public EtherDevice
     }
 
     IGbE(const Params *params);
-    ~IGbE() {}
+    ~IGbE();
     virtual void init();
 
     virtual EtherInt *getEthPort(const std::string &if_name, int idx);
index 4dc4aeae9fe211788ca360f9a3a2003dce646dbb..4a459c6c673ce12c1d38011a1f2ca6ef9ae016d0 100644 (file)
@@ -135,7 +135,9 @@ NSGigE::NSGigE(Params *p)
 }
 
 NSGigE::~NSGigE()
-{}
+{
+    delete interface;
+}
 
 /**
  * This is to write to the PCI general configuration registers
index ab891296fc18961cc49fde45010babd394bdd8e8..6fa22c9b47315838c0fbaa8c0b2da04110c09bd4 100644 (file)
@@ -460,4 +460,6 @@ MSHR::print(std::ostream &os, int verbosity, const std::string &prefix) const
 
 MSHR::~MSHR()
 {
+    delete[] targets;
+    delete[] deferredTargets;
 }
index 873883c1b3e3a57053dab8e1d90c02c3abb76946..3a1246ce71a91624c01b54b8aa80111dc8605d85 100644 (file)
@@ -98,6 +98,14 @@ FALRU::FALRU(unsigned _blkSize, unsigned _size, unsigned hit_latency)
     //assert(check());
 }
 
+FALRU::~FALRU()
+{
+    if (numCaches)
+        delete[] cacheBoundaries;
+
+    delete[] blks;
+}
+
 void
 FALRU::regStats(const string &name)
 {
index 78f9ce1b47006ef475cbff5940fff1c9919be589..fa1f49a42f45f05e8019caf2de04b5f984f9a8fd 100644 (file)
@@ -156,6 +156,7 @@ public:
      * @param hit_latency The hit latency of the cache.
      */
     FALRU(unsigned blkSize, unsigned size, unsigned hit_latency);
+    ~FALRU();
 
     /**
      * Register the stats for this object.
index 260b891945d37bc75676cc17371176e73e2e3436..d6ddf04a6e67d1c1e8ebe217c3e320d988e2fea8 100644 (file)
@@ -160,6 +160,7 @@ IIC::~IIC()
     delete [] dataStore;
     delete [] tagStore;
     delete [] sets;
+    delete [] dataBlks;
 }
 
 /* register cache stats */
index f47e73c7466369c974d7e60d048f89da4a8ddf41..be862e429baabf4ebd7ebee1cfd0a566a42093f3 100644 (file)
@@ -228,6 +228,7 @@ PageTable::unserialize(Checkpoint *cp, const std::string &section)
         entry = new TheISA::TlbEntry();
         entry->unserialize(cp, csprintf("%s.Entry%d", name(), i));
         pTable[vaddr] = *entry;
+        delete entry;
         ++i;
     }
 }
index 30655e6922946a2ef2b5e5f61315b6a452c60552..54b7926d69e96c454fe9d0de291120d454da4dad 100644 (file)
@@ -613,6 +613,10 @@ Checkpoint::Checkpoint(const string &cpt_dir)
     }
 }
 
+Checkpoint::~Checkpoint()
+{
+    delete db;
+}
 
 bool
 Checkpoint::find(const string &section, const string &entry, string &value)
index 46e546be434a71bddabe4b91c7ec72153fffb893..fdb0f4033f7d6ec6266fce5a8d0d4bafeb733043 100644 (file)
@@ -254,6 +254,7 @@ class Checkpoint
 
   public:
     Checkpoint(const std::string &cpt_dir);
+    ~Checkpoint();
 
     const std::string cptDir;